//author: Tao Sun
要對一格字符串分割,本來可以用split,但是要指定多個分割字符的話就要用StringTokenizer了.下面是個簡單的程序測試,分別用漢字逗號和英文逗號分割字符串.
String abc = new String("因子1,因子2,因子3");
try {
StringTokenizer tokenizer = new StringTokenizer(abc, ",,");//can add more in the delim
while (tokenizer.hasMoreTokens()) {
String yz= tokenizer.nextToken();
System.out.println("result: " + yz);
}
}
catch (Exception ee) {
System.out.println(ee.toString());
}
要對一格字符串分割,本來可以用split,但是要指定多個分割字符的話就要用StringTokenizer了.下面是個簡單的程序測試,分別用漢字逗號和英文逗號分割字符串.
String abc = new String("因子1,因子2,因子3");
try {
StringTokenizer tokenizer = new StringTokenizer(abc, ",,");//can add more in the delim
while (tokenizer.hasMoreTokens()) {
String yz= tokenizer.nextToken();
System.out.println("result: " + yz);
}
}
catch (Exception ee) {
System.out.println(ee.toString());
}