问题描述
过去 4 个月我一直在开发一个 Android 应用程序,并且遇到了以下有关拆分功能的问题:
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("|");
结果变量是我在访问我的 WebService 后得到的,现在它可以完美运行.但是,由于某种原因,我的 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] 是H",arr[1] 是e",等等......
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.
提前致谢
推荐答案
arr = result.toString().trim().split("\|");
String.split 的参数接受一个正则表达式.
the param of String.split accept a regular expression.
这篇关于Android 拆分无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!