2016-08-14 53 views
-3

好吧,我已經編寫了將段落拆分成句子的代碼。下面是。但是現在我想用「split」這個詞分開句子。但是如何?.split()在循環?這可能嗎?

import java.util.*; 
import java.util.regex.*; 

public class sub { 
    public static void main(String[] args) { 
     String test ="As World War split II loomed after 1938, with the Japanese invasion split of China and the aggression of Nazi Germany, Roosevelt gave strong diplomatic split and financial support to China and the United Kingdom, while remaining split officially neutral"; 

     String[] sHolder = test.split("[.,?]"); 
     for (int i = 0; i < sHolder.length; i++){ 
      sHolder [i] = sHolder[i].replaceAll("\\[a-z]", ""); 
     } 
} 
+1

不確定一個句子應該被分成','。你可以按空格分成單詞。 –

+1

好吧,只要改變你的正則表達式。如果你想拆分''split'',那麼問題是什麼? – kamoroso94

回答

1

通過使用分裂(),併爲其分配您正則表達式在這種情況下,你希望它分割處is'split」字符串。然後,我們只需將其分配給String[]並循環打印出所有內容。

public static void main(String[] args) throws Exception 
{ 
    String test ="As World War split II loomed after 1938, with the 
        Japanese invasion split of China and the aggression of 
        Nazi Germany, Roosevelt gave strong diplomatic split and 
        financial support to China and the United Kingdom, while 
        remaining split officially neutral"; 

    String[] splitString = test.split("split"); 

    for (String s : splitString) 
    { 
     System.out.println(s); 
    } 
}