Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android split not working correctly

Tags:

android

split

I've been developing an Android app for the past 4 Months now and came across the following regarding the split function:

String [] arr;
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
arr = result.toString().trim().split("|");

The result variable is what I get after accessing my WebService, now this works perfectly. But, for some reason my split("|") method is not splitting at "|" but rather splitting at every single char in my result String. So my array looks like this:

arr[0] is "H", arr[1] is "e", etc......

I don't know why this is happening because I have used it before in the same project and it worked perfectly.

Thank you in advance

like image 449
Jannik Avatar asked Aug 06 '11 08:08

Jannik


2 Answers

arr = result.toString().trim().split("\\|");

the param of String.split accept a regular expression.

like image 99
Changwei Yao Avatar answered Oct 19 '22 07:10

Changwei Yao


Following code can be used for any pattern splitting.

String.split(Pattern.quote("any pattern you would like here !"));
like image 32
user1306828 Avatar answered Oct 19 '22 08:10

user1306828