我想在java中使用它的令牌拆分字符串。例如: ;字符串令牌化
String s = "A#B^C&D!ased&[email protected]%"
String temp[] = s.split("[#^&[email protected]%]+");
Current output :-
temp[0] = A
temp[1] = B
temp[2] = C
temp[3] = D
temp[4] = ased
output which i want :-
temp[0] = A#
temp[1] = B^
temp[2] = C&
temp[3] = D!
temp[4] = ased&
My current approach of doing is
pos = find the index of the token in string
pos = add the size of the token in pos
charAtPos = getcharfrom string at index pos
token = token + charAtPos
如果你有什麼更好的辦法可以提示。我認爲這種方法在非常大的字符串上效率不高。
但它在我的情況下工作正常。它按預期返回結果,但我想要帶有分隔符的令牌 – 2013-04-30 13:27:33