Sunday, 15 July 2012

string - Java StringTokenizer -



string - Java StringTokenizer -

i have next input (11,c) (5,) (7,ab) need split them 2 part each coordinates. intarray should have 11, 5, 7 , letter array should have c,,ab

but when seek using stringtokenizer, intarray should have 11, 5, 7 , letter array should have c,ab

is there way empty part of (5,)? give thanks you.

vector<string> points = new vector<string> (); string = "(11,c) (5,) (7,ab)"; stringtokenizer st = new stringtokenizer(a, "(,)"); while(st.hasmoretokens()) { points.add(st.nexttoken()); } } system.out.println(points);

list <integer> digits = new arraylist <integer> (); list <string> letters = new arraylist <string> (); matcher m = pattern.compile ("\\((\\d+),(\\w*)\\)").matcher (string); while (m.find ()) { digits.add (integer.valueof (m.group (1))); letters.add (m.group (2)); }

java string split

No comments:

Post a Comment