繁体   English   中英

Android split()在模拟器上有效,但在设备上无效

[英]Android split() works on Emulator but not on device

目前,我在使用str.split()函数时str.split()一个奇怪的问题。 首先,这是我的代码:

     String[] seperated = content.split("<div id=\"results\" style=\"width: 175px; \">");
             Log.d("seperated length", "" + seperated.length);



             if(seperated.length>1){
                 Log.d("sep1 t2.", seperated[1]);

                 String[] sep2 = seperated[1].split("<div id=\"map\" ");

                 Log.d("sep2 t1", sep2[0]);

                 String[] sep3 = sep2[0].split("<div class=\"resultLine\">");
                 result = new String[sep3.length];
                 for(int i=1; i<sep3.length; i++){
                    String[] temp = sep3[i].split("class=\"icon1\">");
                    String[] temp2 = temp[1].split("<br>");
                    String[] temp3 = temp2[1].split("<br");
                    String[] temp4 = temp3[0].split("</a>");
                    result[i-1] = temp2[0] + " " +temp4[0];
                    Log.d("places", result[i-1]);


                 }
                 handler.sendEmptyMessage(0);
             } else {
                handler.sendEmptyMessage(1);

             }

在仿真器上,结果数组的生成没有问题,但是在设备上,第一次拆分失败,没有错误或其他任何错误。 字符串内容与模拟器上的内容相同。

使用StringUtils.split()拆分字符串,而不是内置的String方法。 String.split()参数是一个正则表达式(需要正确转义特殊字符等)这一事实会导致很多错误。

您真的不想在这里搞砸正则表达式,只想将字符串分隔成标记,对吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM