parse int from string

J

J M

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!
 
A

Abrasive Sponge

J said:
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.

:)
 
P

PaulR

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.
 
P

PaulR

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.
 
B

Betty

Abrasive Sponge said:
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"?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top