Reputation: 25
Can someone edit this to look better? Thanks!
I'm trying to have a string that is a Hex value but it is set by a third party (Not The Code Itself) and set it back to an int but still be a Hex value. C# Will let you have an int that is equal to a Hex if you have the 0x in front.
Code:
string HexValue = "0x0FC";
int OtherValue = Convert.ToInt(HexValue);
When I try this I get: 'Input string was not in a correct format.'
Upvotes: 0
Views: 3383
Reputation: 4632
You can convert string into a int hex value by adding this System.Globalization.NumberStyles.HexNumber
:
string HexValue = "0x0FC";
int OtherValue = int.Parse(HexValue.Substring(2),System.Globalization.NumberStyles.HexNumber);
Hope it helps!
Upvotes: 1