我正在分割一个字符串,中间有一些示例文本。但它并没有分裂。请帮助我出错的地方
String[] str;
parts[1] = "loopstWatch out this is testingloopstThis makes the difference";
str = parts[1].trim().split("loopst");
答案 0 :(得分:0)
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 :(得分:0)
我认为你是倒退了。
你想首先拆分,然后在索引1处得到一块,然后修剪,然后将str设置为等于结果:
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"