I usually use String.split(...) rather than StringTokenizer. You can't use "|%" as a delimiter without escaping the '|' character since it has meaning in regular expressions. Thus "\\|%" can be used as a delimiter, but even so, the delimiter will be swallowed when you split your String, so the output will be
col1
col2
For instance:
|
Code:
|
public class Fu1 {
public static void main(String[] args) {
String test = "col1|%col2|%|%";
String[] tokens = test.split("\\|%", -1);
for (String token : tokens) {
System.out.println(token);
}
}
} |