Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > parse int from string

Reply
Thread Tools

parse int from string

 
 
J M
Guest
Posts: n/a
 
      04-28-2005
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!


 
Reply With Quote
 
 
 
 
Abrasive Sponge
Guest
Posts: n/a
 
      04-28-2005
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.


 
Reply With Quote
 
 
 
 
PaulR
Guest
Posts: n/a
 
      04-28-2005
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.

 
Reply With Quote
 
PaulR
Guest
Posts: n/a
 
      04-28-2005
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.

 
Reply With Quote
 
Betty
Guest
Posts: n/a
 
      04-29-2005

"Abrasive Sponge" <> wrote in message
news:ue-dnaKHEJ8g2-3fRVn-...
> 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"?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
map question - need to find a string from an int but also need the int from the string? Angus C++ 3 05-03-2008 02:27 PM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57