J2ME字符串split方法
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 15:37 点击:次
Java代码
/**
* Split string into multiple strings
* @param original Original string
* @param separator Separator string in original string
* @return Splitted string array
*/
private String[] split(String original, String separator) {
Vector nodes = new Vector();
// Parse nodes into vector
int index = original.indexOf(separator);
while(index>=0) {
nodes.addElement( original.substring(0, index) );
original = original.substring(index+separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement( original );
// Create splitted string array
String[] result = new String[ nodes.size() ];
if( nodes.size()>0 ) {
for(int loop=0; loop<nodes.size(); loop++)
result[loop] = (String)nodes.elementAt(loop);
}
return result;
}
/**
* Split string into multiple strings
* @param original Original string
* @param separator Separator string in original string
* @return Splitted string array
*/
private Vector split2Vector(String original, String separator) {
Vector nodes = new Vector();
// Parse nodes into vector
int index = original.indexOf(separator);
while(index>=0) {
nodes.addElement( original.substring(0, index) );
original = original.substring(index+separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement( original );
return nodes;
}
本文出自 “技术人生” 博客,请务必保留此出处http://zhaohaiyang.blog.51cto.com/2056753/435627
相关新闻>>
- 发表评论
-
- 最新评论 更多>>