CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: int.Parse

  1. #1
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102

    int.Parse

    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?

  2. #2
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Code:
    int i = Int32.Parse("A", System.Globalization.NumberStyles.AllowHexSpecifier);
    Martin

  3. #3
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    Great. It works perfect. Thanks

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    alternatively,

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

    -Paresh

  5. #5
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    can I use Convert() to convert any base?

  6. #6
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    yes
    2 , 8 16 etc.. octal, int, decimal 10 , hex 16 ...

    Paresh

  7. #7
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    cool. nice to know that, thanks

  8. #8
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured