parse int from string

Discussion in 'Java' started by J M, Apr 28, 2005.

  1. J M

    J M Guest

    How do I go about parsing integers from following form?

    (a:3, b:4) (b:4, c:2) (c:2, d9) ... and so on

    If I can I like to process two ints at a time for example 3 and 4 then move
    on to 4 and 2 and so on...

    TIA!
    J M, Apr 28, 2005
    #1
    1. Advertising

  2. J M wrote:
    > How do I go about parsing integers from following form?
    >
    > (a:3, b:4) (b:4, c:2) (c:2, d9) ... and so on
    >
    > If I can I like to process two ints at a time for example 3 and 4 then move
    > on to 4 and 2 and so on...
    >
    > TIA!
    >
    >


    public void bushSucks(String s, Hashtable h) {
    int index = s.indexOf(':');
    String letter = "" + s.charAt(index-1);
    int number = Integer.parseInt("" + s.charAt(index+1));
    h.put(letter, number);
    woot(s.substring(s.indexOf(')')) + 1, s.length(), h);
    }


    eh, somephin like that I guess. Not the best solution, but since I am
    assuming you are a student. It would be best for you to find a better way.

    :)
    Abrasive Sponge, Apr 28, 2005
    #2
    1. Advertising

  3. J M

    PaulR Guest

    I'm sure you could do something with regular expressions here.

    Something like "\(.*?\)" to get the bracketed groups. Then "\d" to get
    the digit groups.
    PaulR, Apr 28, 2005
    #3
  4. J M

    PaulR Guest

    I'm sure you could do something with regular expressions here.

    Something like "\(.*?\)" to get the bracketed groups. Then "\d" to get
    the digit groups.
    PaulR, Apr 28, 2005
    #4
  5. J M

    Betty Guest

    "Abrasive Sponge" <> wrote in message
    news:...
    > J M wrote:
    > > How do I go about parsing integers from following form?
    > >
    > > (a:3, b:4) (b:4, c:2) (c:2, d9) ... and so on
    > >
    > > If I can I like to process two ints at a time for example 3 and 4 then

    move
    > > on to 4 and 2 and so on...
    > >
    > > TIA!
    > >
    > >

    >
    > public void bushSucks(String s, Hashtable h) {
    > int index = s.indexOf(':');
    > String letter = "" + s.charAt(index-1);
    > int number = Integer.parseInt("" + s.charAt(index+1));
    > h.put(letter, number);
    > woot(s.substring(s.indexOf(')')) + 1, s.length(), h);
    > }


    Is the "d9" part a typo? Should it be "d:9"?
    Betty, Apr 29, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,189
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,605
    Old Wolf
    Jan 20, 2004
  3. Replies:
    19
    Views:
    1,092
    Daniel Vallstrom
    Mar 15, 2005
  4. arun
    Replies:
    8
    Views:
    426
    Dave Thompson
    Jul 31, 2006
  5. aling
    Replies:
    8
    Views:
    927
    Jim Langston
    Oct 20, 2005
Loading...

Share This Page