2017-02-15 84 views
-1

我一直在試圖提取「靠近甘戈特里醫院」的一部分,「無125/6 8萬里巴士站」,但我不能夠提取它可以在任何一個請幫我解壓字符串如何提取「線」的Android

我需要提取3次串這是後第二管道(|)運算符。

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(「|」);'因爲pipe是一個正則表達式中的特殊字符。我認爲你需要做'text.split(Pattern.quote( 「|」));' – Orin

+0

字符串部分[] = text.split( 「\\ |」); –