我一直在开发一个Android应用程序,在过去4个月了,并遇到了以下有关拆分功能:
的String [] ARR;
SoapPrimitive结果=(SoapPrimitive)envelope.getResponse();
。ARR = result.toString()修剪()分裂(|)。
结果变量是访问我的web服务后,我得到了,现在这个完美的作品。但是,由于某种原因,我的分裂(|)方法不是分裂的|而是分裂在我的结果字符串的每一个字符。所以,我的数组是这样的:
改编[0]为H, ARR [1]为E, 等等......
我不知道为什么会这样,因为我在同一个项目中使用它之前,它的工作完美。
感谢你在前进
。解决方案 ARR = result.toString()修剪()分裂(\\ |);
String.split的参数接受正规的前pression。
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
解决方案arr = result.toString().trim().split("\\|");
the param of String.split accept a regular expression.