CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    California
    Posts
    264

    How to concert String to int?

    How to concert String to int? I've tried to use parseInt() and valueOf(), but it can not work.

    thank you!

    Best Regards,

    Kevin Shen
    Best Regards,

    Kevin Shen

  2. #2
    Join Date
    Jun 1999
    Location
    Germany (south)
    Posts
    147

    Re: How to concert String to int?

    Hi Kevin,

    may be you used parseInt () in a wrong way.
    Try this (I am sure this works, I use this code - if not, contact me again!!!):

    Integer aInt = null;
    int tmp = aInt.parseInt(aString);




    Another possibility (I use this as well) is following:

    String wrapperString = "2";
    Integer wrapperInt;
    int wrapperIntResult;
    wrapperInt = Integer.valueOf(wrapperString);
    wrapperIntResult = wrapperInt.intValue();





    Andi


  3. #3
    Join Date
    Jun 1999
    Posts
    126

    Re: How to concert String to int?

    Try

    String str = "12345";
    Integer ii = new Integer(str);
    int i = ii.intValue();




    Timo


  4. #4
    Join Date
    Sep 2000
    Location
    Melbourne --> Australia
    Posts
    68

    Re: How to concert String to int?

    Integer.parseInt("1243");//returns an int
    Float.parseFloat("12.23");//returns a float
    Byte.parseByte("12");//returns a byte
    Long.parseLong("12543241");//returns a long
    Double.parseDouble("12355.3");//returns a double
    All of the "wrapper" classes have the equivalent method except for Character.
    Phill.


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