明辉站/网站教程/内容

j2me中StringToKenizer的替代方法[原创]

网站教程2024-01-23 阅读
[摘要]j2me的String类中没有StringToKenizer如此重要的类,而事实上,在rms的读取数据过程中经常会用到字符串的分割这里我写了一个功能类似的函数,共享出来// split a string with symblo,return vecotrpublic Vector stringSp...
j2me的String类中没有StringToKenizer如此重要的类,
而事实上,在rms的读取数据过程中经常会用到字符串的分割
这里我写了一个功能类似的函数,共享出来

// split a string with symblo,return vecotr
public Vector stringSplit(String symbol, String source) {
Vector tmp = new Vector();
String str = source;
int length = str.length();
int slen = symbol.length();
int index = 0;
int start = 0;
while ( (index = str.indexOf(symbol)) != -1 ) {
tmp.add(str.substring(start, index));
str = str.substring(index+slen, length);
length = str.length();
start = index+slen;
}
tmp.add(str);
return tmp;
}

……

相关阅读