2016-08-14 24 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); 
    } 
}