我正在分割一个字符串,中间有一些示例文本。但它不是分裂。请帮助我哪里出错了
String[] str;
parts[1] = "loopstWatch out this is testingloopstThis makes the difference";
str = parts[1].trim().split("loopst");
我正在分割一个字符串,中间有一些示例文本。但它不是分裂。请帮助我哪里出错了
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 处获取片段,然后修剪,然后将 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"