H
Hanif
Hi folks,
I am trying to use the split on a String, the result returns an
array of Strings. I always get the first String in the array as an
empty string.
Please note that the StringTokenizer did not work, but with using
split i am very close to the number of token i want.
Any Ideas !
Thanks a lot
Hanif
---------------------------------------------------------------------------
Here is some code that would illustrate the problem:
String data="XXXX:aaaaaaa\nbbbbbbb\nXXXX:cccccc\nddddd\nXXXX:eeeeee\nffffff\n";
String t_data=data.trim();
String[] TOKENS = t_nodeData_.split("XXXX:");
System.out.println("TOKENS.length : " + TOKENS.length);
System.out.println("TOKENS[0].length : " + TOKENS[0].length());
for(int i = 0; i < TOKENS.length; i++) {
System.out.println("TOKENS["+i+"] :"+TOKENS);
}
Result :
t_data :
XXXX:aaaaaaa
bbbbbbb
XXXX:cccccc
ddddd
XXXX:eeeeee
ffffff
TOKENS.length : 4
TOKENS[0].length : 0
TOKENS[0] :
TOKENS[1] :aaaaaaa
bbbbbbb
TOKENS[2] :cccccc
ddddd
TOKENS[3] :eeeeee
ffffff
I am trying to use the split on a String, the result returns an
array of Strings. I always get the first String in the array as an
empty string.
Please note that the StringTokenizer did not work, but with using
split i am very close to the number of token i want.
Any Ideas !
Thanks a lot
Hanif
---------------------------------------------------------------------------
Here is some code that would illustrate the problem:
String data="XXXX:aaaaaaa\nbbbbbbb\nXXXX:cccccc\nddddd\nXXXX:eeeeee\nffffff\n";
String t_data=data.trim();
String[] TOKENS = t_nodeData_.split("XXXX:");
System.out.println("TOKENS.length : " + TOKENS.length);
System.out.println("TOKENS[0].length : " + TOKENS[0].length());
for(int i = 0; i < TOKENS.length; i++) {
System.out.println("TOKENS["+i+"] :"+TOKENS);
}
Result :
t_data :
XXXX:aaaaaaa
bbbbbbb
XXXX:cccccc
ddddd
XXXX:eeeeee
ffffff
TOKENS.length : 4
TOKENS[0].length : 0
TOKENS[0] :
TOKENS[1] :aaaaaaa
bbbbbbb
TOKENS[2] :cccccc
ddddd
TOKENS[3] :eeeeee
ffffff