I really don't have the idea on why I am getting 0
value on this:
But this code works well:
int val = Convert.ToInt32("1546");
Here is the appsetting:
<add key="PesoPayMerchantId" value="1546"/>
Any idea?
Edit1
I want to get the integer value of "1546"
, but it fails to work.
Here is the code for getting appsetting:
public static string GetConfigurationString(string appSettingValue)
{
return ConfigurationManager.AppSettings[appSettingValue];
}
I have tried your suggestions, and this is the result:
The string value is correct ("1546")
, but it can't be parse to integer. What is happening here?
Edit 2
I am very sure that the value of:
<add key="PesoPayMerchantId" value="1546"/>
is really a combination of numbers "1546"
But when I try to re-write the string value using Immediate Window
it can now be parsed. But still I can't figure out the very reason of this Bug
?
Edit 3
Finally, it works now, thanks to Johnny
What I did is, I re-write the whole, <add key="PesoPayMerchantId" value="1546"/>
and it can now be parsed. Thanks for all your help. :D
By default, strings that represent integer values are parsed by using the NumberStyles.Integer value, which permits only numeric digits, leading and trailing white space, and a leading sign. Strings that represent floating-point values are parsed using a combination of the NumberStyles.Float...
If a numeric parsing method is passed a string that contains any other digits, the method throws a FormatException. The following example uses the Int32.Parse method to parse strings that consist of digits in different writing systems.
The method generally used to convert String to Integer in Java is parseInt (). There are two variants of this method: 1. parseInt (String s): This function parses the string argument as a signed decimal integer.
The currency symbol is permitted. The currency symbol is defined by the NumberFormatInfo.CurrencySymbol property. The string to be parsed is interpreted as a hexadecimal number. It can include the hexadecimal digits 0-9, A-F, and a-f. This flag can be used only to parse integer values.
The answer would be, re-write the config.
As I remember, I just copied and paste
"1546"
from a pdf file.
So lesson learned, don't be too lazy on typing values.
Additional Information:
I also remember that, I did copy and paste
on gmail
(google Chrome)
and I found out that the text I copied contains hidden characters
at the beginning.
I can only think that you are experiencing some kind of weird globalization / Culture specific problem.
Given that you know the exact format of the number, you might try the Int32.TryParse Method (String, NumberStyles, IFormatProvider, Int32)
overload, e.g.:
int.TryParse(val, NumberStyles.Any, CultureInfo.InvariantCulture, out id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With