0

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#.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

It is still not working. The error is coming up as: Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)
It is showing a run time exception as: FormatException was unhandled. Input String was not in the correct format.
It doesn't like the "0x", see above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.