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
만약 더 좋은 방법이 있다면 제안하십시오. 나는 매우 큰 문자열에 대한 접근 방식이 그리 효율적이지 않다고 생각합니다. 그래서 어쩌면 [#|^|&|!|@|%]
하지만 제 경우에는 정상적으로 작동합니다. 예상대로 결과를 반환하지만 나는 구분 기호로 토큰을 원한다. –