2017-05-06 61 views
-2

字符串我有一個像波紋管提取的java

String s = "A<>B<>C<>D<>" 

和A,B,C,d的字符串是未知 欲分離「C」 根據該信息,這是第二個之間和第三個「<>」我該怎麼辦?

回答

5
String[] parts = s.split("<>"); 
String wanted = parts[2]; 
1

替代使用split

int first = s.indexOf("<>"); 
int second = s.indexOf("<>", first + 2); 
int third = s.indexOf("<>", second + 2); 

String wanted = s.substring(second + 2, third); 
+0

感謝,我有一個關於這個問題的方法,你爲什麼要加+2? – pooyathr

+0

嘗試不帶+2。 –