Results 1 to 7 of 7
  1. #1
    gonzoateafly is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Basic string problem, just need to extract two numbers out of string

    Howdy all,

    I have a fairly basic question. I'm terrible with strings, so I could really use some help. :)

    I have some strings that contain two values I need to extract (coordinates):
    "(153, 563)"

    The numbers can be any size.

    All I need to do is extract the two integers out of the string.

  2. #2
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    String str = "12234,789";
    int1 = Integer.parseInt(str.substring(0, str.indexOf(',')));
    int2 = Integer.parseInt(str.substring(str.indexOf(',')+1, str.length()));

  3. #3
    Join Date
    Jul 2010
    Location
    India
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by jomypgeorge View Post
    String str = "12234,789";
    Alternative way ... :p

    Java Code:
         String[] strArray  = str.split(",");
           int a1 = Integer.parseInt(strArray[0]);  
           int a2 = Integer.parseInt(strArray[1]);
    _______________________________________________
    give me beans .........

  4. #4
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    thanks vinod

  5. #5
    gonzoateafly is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Good deal, that took care of it, thanks guys!

  6. #6
    Join Date
    Jul 2010
    Location
    India
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by jomypgeorge View Post
    thanks vinod
    Welcome Jomy...


    Happy Coding
    _______________________________________________
    give me beans .........

  7. #7
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

Similar Threads

  1. Basic String Help
    By JazzyJ in forum New To Java
    Replies: 1
    Last Post: 11-15-2010, 11:50 AM
  2. Replies: 5
    Last Post: 06-22-2010, 10:34 AM
  3. String Tokenizer - Basic email validation
    By bobbyboyy in forum New To Java
    Replies: 3
    Last Post: 11-01-2009, 05:44 PM
  4. add all the numbers in a string
    By gibson.nathan in forum New To Java
    Replies: 29
    Last Post: 09-30-2009, 07:14 PM
  5. Extract item from a string
    By firewalll in forum New To Java
    Replies: 2
    Last Post: 09-02-2009, 06:00 AM

Posting Permissions

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