Android的拆分工作不正常 [英] Android split not working correctly

查看:115
本文介绍了Android的拆分工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个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.

这篇关于Android的拆分工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆