I am trying to use StrTokenizer for some parsing and I am probably not using
it correctly.
Let's say I have this string:
11"a,b"11,22"c,d"22"
I would like to split it by the comma ",", but ignoring any commas embedded
in quotes. I try this:
String test = "11\"a,b\"11,22\"c,d\"22";
StrTokenizer str = new StrTokenizer(test,',','"');
String[] tokens = str.getTokenArray();
for(String t: tokens) {
System.out.println(t);
}
and expect to have two strings print out:
11"a,b"11
22"c,d"22
but instead I get 4 :
11"a
b"11
22"c
d"22
It seems the tokenizer is splitting on the comma, even if it is embedded in
quotes.
I tried different options on the StrTokenizer, but not been able to get it
to work correctly.
Any idea as to what am I doing wrong? Using latest version 2.4.
Thanks, Jacek