String s="fdsaf,fdsew,fwio,oijf";
StringTokenizer st=new StringTokenizer(s,",");//其中逗号可用任意多个其它字符代替,如",;'"等
String str=null;
while(st.hasMoreToken()){
str=st.nextToken();
}
StringTokenizer st=new StringTokenizer(s,",");//其中逗号可用任意多个其它字符代替,如",;'"等
String str=null;
while(st.hasMoreToken()){
str=st.nextToken();
}
解决方案 »
- 为什么运行到res.next()这里老是抛出SQLEXcption()求解啊。。。
- Linux(CentOS5,RedHat EL 4)和Windows上的字节问题
- 问一个关于正则表达式的问题, 谢谢大家!
- 如何截取视频的第一帧图片?
- Java打印时的字体控制问题...
- 大虾们我有个关于JList中的每一项添加一个隐藏值,就是同时向一项中添加两个值一个显示一个不显示
- 当选择某菜单项时,希望能调用出panel 面板,可就是不出来,为什么?谢谢大家帮忙
- 请教一个关于jsdk1.4.0 -b92的中文问题。
- Sun 公司去死。。。
- 编写的脚本放到哪个盘里最好呢?
- MM有礼了!GG帮忙!
- win98 下如何永久设置环境变量
int index = 0;
boolean matchLimited = limit > 0;
ArrayList matchList = new ArrayList();
Matcher m = matcher(input); // Add segments before each match found
while(m.find()) {
if (!matchLimited || matchList.size() < limit - 1) {
String match = input.subSequence(index, m.start()).toString();
matchList.add(match);
index = m.end();
} else if (matchList.size() == limit - 1) { // last one
String match = input.subSequence(index,
input.length()).toString();
matchList.add(match);
index = m.end();
}
} // If no match was found, return this
if (index == 0)
return new String[] {input.toString()}; // Add remaining segment
if (!matchLimited || matchList.size() < limit)
matchList.add(input.subSequence(index, input.length())); // Construct result
int resultSize = matchList.size();
if (limit==0)
while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
resultSize--;
String[] result = new String[resultSize];
return (String[])matchList.subList(0, resultSize).toArray(result);
}
return split(input, 0);
}JDK上的源码
split(CharSequence input)??不明白啊。
用StringTokenizer这个类来实现,例:
/*
* Created on 2004-7-5
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package temp;import java.util.StringTokenizer;/**
* @author wx
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class Temp { public static void main(String[] args) {
String str = "one#tow#three#four";
StringTokenizer st = new StringTokenizer(str, "#");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}