2017-03-16 48 views
-6

那麼怎麼能在android中拆分這個組合呢?如何拆分包含( n:,。)的字符串

在此先感謝:)`

我試圖像String lines[] = String.split("\\r?\\n", -1); 但在同一時間如何分割的所有數據

+1

'String#split'支持正則表達式,正則表達式支持'或'表達式 – SomeJavaGuy

+2

Pos [Java正則表達式或運算符]的sible副本(http://stackoverflow.com/questions/2031805/java-regular-expression-or-operator) – Manu

+0

[如何在Java中分割字符串](http:///stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) –

回答

0

您可以使用模式的正則表達式拆分

String fields = "name[Employee Name], employeeno[Employee No], dob[Date of 
Birth], joindate[Date of Joining]"; 

Pattern pattern = Pattern.compile("\\[.+\\]+?,?\\s*"); 

String[] split = pattern.split(fields); 

參考:How to split this string using Java Regular Expressions

相關問題