String toEmailAddress="[email protected],efg.sohu.com,[email protected]";
StringTokenizer st=new StringTokenizer(toEmailAddress,",");
while(st.hasMoreToken){
String toAddr=st.nextToken();
System.out.println(toAddr);
//some other operation.
}
StringTokenizer st=new StringTokenizer(toEmailAddress,",");
while(st.hasMoreToken){
String toAddr=st.nextToken();
System.out.println(toAddr);
//some other operation.
}
在JDK1.4上,用 String.split(","),就可以实现上面的功能了。
[email protected]可以分解成"aa","163","com"
另外:
我根据pigo说的测试了一下split,它支持正则式,所以显得更灵活和标准,
比如 实现多个分解符
str = [email protected]
用 new StringTokenizer(str,"@."); //语法不好,@.就有两个意思了,呵呵!
用 str.split("[\\.@]"); //.或者@,这就严格多了