Facepalm of the day.
-
Jörgen Andersson wrote:
But since it didn't throw an exception but rather make a correct conversion
What version of .NET? I've just tried
Convert.ToInt32("42.")
in LINQPad for 3.5 and 4.5, and both versions throw aFormatException
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
4.5
Wrong is evil and must be defeated. - Jeff Ello[^]
-
4.5
Wrong is evil and must be defeated. - Jeff Ello[^]
Weird. If I try
Convert.ToInt32("42.")
in .NET 4.5, I get:FormatException: Input string was not in a correct format.
Are you sure you're not doing something else in your code that's hiding the error?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Weird. If I try
Convert.ToInt32("42.")
in .NET 4.5, I get:FormatException: Input string was not in a correct format.
Are you sure you're not doing something else in your code that's hiding the error?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Odd, I'have to check on monday when I'm back at work.
Wrong is evil and must be defeated. - Jeff Ello[^]
-
Weird. If I try
Convert.ToInt32("42.")
in .NET 4.5, I get:FormatException: Input string was not in a correct format.
Are you sure you're not doing something else in your code that's hiding the error?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Jörgen Andersson (is this you "Neo"?!?) sounds scandinavian and they probably have a different decimal separator... Robert
-
Jörgen Andersson (is this you "Neo"?!?) sounds scandinavian and they probably have a different decimal separator... Robert
Good point. However,
Convert.ToInt32("42,")
still produces aFormatException
. Trying "42." with the "sv-SE" culture, which uses "," as the decimal separator and "." as the group separator, also produces aFormatException
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
So I was building an application that presents a list of files matched with info in a database. Everything was working fine and dandy but horrendously slow. I quickly found the culprit to be in this function:
Func GetIDPart_Of_FileName = FileName => Convert.ToInt32(FileName.Substring(FileName.IndexOf('_') + 1, FileName.IndexOf('.') - FileName.IndexOf('_')));
The files are built in the form of ID_AnotherID.Extension and what I wanted was AnotherID Can anyone see what I did wrong? :) Do note that it was giving correct results. fixed typo
Wrong is evil and must be defeated. - Jeff Ello[^]
hmm FileName.IndexOf('_') is calculated twice too
-
So I was building an application that presents a list of files matched with info in a database. Everything was working fine and dandy but horrendously slow. I quickly found the culprit to be in this function:
Func GetIDPart_Of_FileName = FileName => Convert.ToInt32(FileName.Substring(FileName.IndexOf('_') + 1, FileName.IndexOf('.') - FileName.IndexOf('_')));
The files are built in the form of ID_AnotherID.Extension and what I wanted was AnotherID Can anyone see what I did wrong? :) Do note that it was giving correct results. fixed typo
Wrong is evil and must be defeated. - Jeff Ello[^]
Well, a little late to the party, but this is why I have a whole bunch of string extensions, like this "Between" and "ToInt32":
FileName.Between('_', '.').ToInt32()
And then you would never have included the '.' by accident. ;) MarcImperative to Functional Programming Succinctly Higher Order Programming
-
Well, a little late to the party, but this is why I have a whole bunch of string extensions, like this "Between" and "ToInt32":
FileName.Between('_', '.').ToInt32()
And then you would never have included the '.' by accident. ;) MarcImperative to Functional Programming Succinctly Higher Order Programming
Just put that on my todo list. :thumbsup:
Wrong is evil and must be defeated. - Jeff Ello[^]
-
Just put that on my todo list. :thumbsup:
Wrong is evil and must be defeated. - Jeff Ello[^]
Send me a direct email and I'll send you the .cs file of my extensions. There's this[^] too. Marc
Imperative to Functional Programming Succinctly Higher Order Programming
-
Well, a little late to the party, but this is why I have a whole bunch of string extensions, like this "Between" and "ToInt32":
FileName.Between('_', '.').ToInt32()
And then you would never have included the '.' by accident. ;) MarcImperative to Functional Programming Succinctly Higher Order Programming
very cool (aka :cool: ) 'g'