我想在 java 中用它的标记分割一个字符串。例如;
String s = "A#B^C&D!ased&acdf@Mhj%"
String temp[] = s.split("[#^&!@%]+");
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
如果你有更好的方法建议。我认为方法在非常大的 Strings 上效率不高。