2017-02-15 2 views
-1

"Near Gangotri hospital"과 "No 125/6 8th Miles Bus Stop"을 추출하려고했지만 어느 것도 추출 할 수 없었습니다. 문자열"string"android의 일부분을 추출하는 방법

두 번째 파이프 (|) 연산자 다음에 나오는 세 번째 문자열을 추출해야합니다.

9649|14:30|Near Gangotri hospital |Opp Central Bank (Test)|9880955077|B T M Layout ~ 8937|14:34|no 125/6 8th Miles Bus Stop|Near 8th Mile Signal|080 65468012222|8th Mile 
+1

하위 문자열 방법을 사용해 보셨습니까? string.substring (11,32); 그것이 가까운 Gangotri 병원을 제공하는지보십시오. 위치와 함께해야 할 수도 있습니다. –

답변

2

String.split(String regex)을 사용하여 텍스트를 분할 한 다음 나중에 원하는 부분을 선택할 수 있습니다.

String text = "9649|14:30|Near Gangotri hospital |Opp Central Bank (Test)|9880955077|B T M Layout ~ 8937|14:34|no 125/6 8th Miles Bus Stop|Near 8th Mile Signal|080 65468012222|8th Mile"; 
String parts[] = text.split("|"); 
String part3 = parts[2]; //Near Gangotri hospital 
+2

파이프가 정규 표현식의 특수 문자이므로'text.split ("|");'을 할 수 없다고 확신합니다. 나는 당신이'text.split (Pattern.quote ("|"));' – Orin

+0

할 필요가 있다고 생각합니다. String parts [] = text.split ("\\ |"); –

관련 문제