Click to See Complete Forum and Search --> : int.Parse


underwar
March 2nd, 2003, 09:02 AM
I'm trying to make the following lines to work:

int i = int.Parse("0xA");
Console.WriteLine(i);

i.e: i want parse to take the hex number, convert it to int and print it.

As I read in the manual, we can add another parameter to Parse - FormatProvider, that will do the task, but I can't understand how to use that FormatProvider.

Anyone has a solution?

MartinL
March 2nd, 2003, 09:27 AM
int i = Int32.Parse("A", System.Globalization.NumberStyles.AllowHexSpecifier);


Martin

underwar
March 2nd, 2003, 09:33 AM
Great. It works perfect. Thanks

pareshgh
March 2nd, 2003, 01:32 PM
alternatively,

int a = Convert.ToInt32("0xA",16);
MessageBox.Show(a.ToString());

-Paresh

underwar
March 2nd, 2003, 01:37 PM
can I use Convert() to convert any base?

pareshgh
March 2nd, 2003, 01:41 PM
yes
2 , 8 16 etc.. octal, int, decimal 10 , hex 16 ...

Paresh

underwar
March 2nd, 2003, 01:44 PM
cool. nice to know that, thanks :)

pareshgh
March 2nd, 2003, 09:50 PM
specially

Convert
and
System.Text... classes are typically very important since they are the most needfull classes to change one data format to another data format.


-Thanx
Paresh