我有一個String
陣列如何在java中將一個沒有空格的字符串分成多個單詞?
String student [] = {"BAT4M0ABBB4M0ABOH4M0CCHI4U0AENG4U0DMDM4U0B"}
我需要拆分此爲每7個字符。 它應該看起來像這樣:
String student {
"BAT4M0A",
"BBB4M0A",
"BOH4M0C",
"CHI4U0A",
"ENG4U0D",
"MDM4U0B"
}
這是我的代碼到目前爲止。
for (int i=0; i<= data.length; i++)
{
student= data[i].split(","); //data is a file of 1000 lines that is being read
if (student [2].equals(sN)) //student is a line in the each file that has been split into 11 parts
{
String timetable[]= student[9].split("(?<=\\G.......)");
System.out.println (timetable);
break;
}
你希望你的最終結果是一個字符串數組嗎? –
Plz看到一個類似的線程 http://stackoverflow.com/questions/12295711/split-a-string-at-every-nth-position –