Results 1 to 3 of 3

Thread: String to integer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2000
    Location
    Reykjavík, Iceland
    Posts
    29

    String to integer

    Í know this should be easy but sometimes you just cant see the light.

    I have string that I need to move to integer variable if it is integer?

    Any idea

    Icesoft

  2. #2
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    String s = "1234";
    int mynumber;
    try
    {
    mynumber = Integer.parseInt(s);
    }
    catch (NumberFormatException e)
    {
    System.out.println("That was not a number");
    }

  3. #3
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    i would use a function:

    Code:
    public int castToInt( String str )
    {
        return( new Integer( str ).intValue() );
    }
    ...that should work just fine.
    To protect time is to protect everything...

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