-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