My program creates couple string hex numbers and saves it to a .ini file on my computer. Now I want to convert them to int32. In my .ini file the hex values are listed this way:
and now I want these values in the same .ini file replaced with the new converted values, like:
That is how i save the values:
using (StreamWriter writer = new StreamWriter(@"C:\values.ini", true))
{
foreach (string key in values.Keys)
{
if (values[key] != string.Empty)
writer.WriteLine("{1}", key, values[key]);
}
}
If your concern is how to parse each of these strings and create the corresponding int for each of them you could try the following:
int val;
if(int.TryParse(str, System.Globalization.NumberStyles.HexNumber, out val))
{
// The parsing succeeded, so you can continue with the integer you have
// now in val.
}
where str
is the string, for instance the "02E8ECB4"
.