-3
我分裂一个字符串与中间的一些示例文本。但它不是分裂。请帮我哪里出了错分裂数组不工作在android
String[] str;
parts[1] = "loopstWatch out this is testingloopstThis makes the difference";
str = parts[1].trim().split("loopst");
我分裂一个字符串与中间的一些示例文本。但它不是分裂。请帮我哪里出了错分裂数组不工作在android
String[] str;
parts[1] = "loopstWatch out this is testingloopstThis makes the difference";
str = parts[1].trim().split("loopst");
String[] arr;
arr = "loopstWatch out this is testingloopstThis makes the difference".trim().split("loopst");
Log.e("Data arr[0]",":"+arr[0]);
Log.e("Data arr[1]",":"+arr[1]);
Log.e("Data arr[2]",":"+arr[2]);
输出
arr[0] :""
arr[1] :"Watch out this is testing"
arr[2] :"This makes the difference"
我觉得你倒着做。
你想第一次分裂,然后得到一张索引1,再修剪一下,然后设置海峡等于结果:
String s = "loopstWatch out this is testingloopstThis makes the difference";
String str = s.split("loopst")[1].trim();
// str should be equal to "Watch out this is testing"
如果我们知道错误信息(或“错误”这将有助于输出“) – michaelb958 2013-04-18 05:05:37
当我试图打印str值时,它什么也没有显示 – user1448108 2013-04-18 05:06:12
所以你想分隔字符串作为'loopst'? – 2013-04-18 05:10:33