Reputation: 145
I have n XML file which has a hexadecimal variable
<settings>
<add key "var1" value "0x0FFFFFFF">
</settings>
And I need to pull the String value from the config and put it into an integer variable
uint Store_var;
Store_var=Integer.parseInt(settings["var1"]);
But it shows an error as:
The name Integer does not exist in the current context.
I tried other methods also. But it isn't working.
Can you please help me how to proceed with it. Or any other method how to store the string value in an integer variable.
It is C#.
Upvotes: 0
Views: 143
Reputation: 803
C#:
uint Store_var = UInt32.Parse(settings["var1"], System.Globalization.NumberStyles.HexNumber)
Java:
int value = Integer.parseInt(settings["var1"], 16);
It also won't parse the 0x so:
string hexString = settings["var1"].ToUpper().Trim();
if (hexString.StartsWith("0X"))
{
hexString = hexString.Substring(2, hexString.Length - 2);
}
uint Store_var = UInt32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
Upvotes: 2