simple string parsing question

M

Marc E

All,
Been a looong time since i've done any string parsing in java. I seem to
remember there being a braindead simple way of turning a string like this:

100,1,1;2598,2,3;25467,1,3

into an array of arrays delimited first on the semicolon and then on the
comma.

Currently, i'm just stringTokenizing it on the semicolon and then doing
next() calls.

So...
StrTokenizer = new StrTokenizer("100,1,1;2598,2,3;25467,1,3",";");
List list = tokenizer.asList()

iterate over list
StrTokenizer newTokenizer = new StrTokenizer(list.next(),",");
List newlist = newTokenizer.asList();
thisVal = newlist.next();
someOtherVal = newlist.next();

and so forth.

it's just damn ugly, so i'm wondering what the best/cleanest way to do this
in java is.

thanks all.

Marc
 
M

Marc E

ugggg, forget it. funny how you go looking in all your little commons helper
packages when it's right there in String.
 
C

CodeForTea

ugggg, forget it. funny how you go looking in all your little commons helper
packages when it's right there in String.













- Show quoted text -

public static String[][] getArrays(String stringVal){
String[] strings= stringVal.split(";");
String[][]arrayOFarrays = new String[strings.length][];
for (int i = 0; i < strings.length; i++) {
arrayOFarrays = strings.split(",");
}
return arrayOFarrays;
}

I am not sure if it is any prettier, but another way of doing it.

Dinesh
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top