j2me中StringToKenizer的替代方法[原創(chuàng)]
發(fā)表時(shí)間:2024-05-31 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]j2me的String類中沒(méi)有StringToKenizer如此重要的類,而事實(shí)上,在rms的讀取數(shù)據(jù)過(guò)程中經(jīng)常會(huì)用到字符串的分割這里我寫(xiě)了一個(gè)功能類似的函數(shù),共享出來(lái)// split a string with symblo,return vecotrpublic Vector stringSp...
j2me的String類中沒(méi)有StringToKenizer如此重要的類,
而事實(shí)上,在rms的讀取數(shù)據(jù)過(guò)程中經(jīng)常會(huì)用到字符串的分割
這里我寫(xiě)了一個(gè)功能類似的函數(shù),共享出來(lái)
// 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;
}