2016-08-14 3 views
-3

私は文章を文章に分割するコードを書いています。これは以下の通りです。しかし今、私は「スプリット」という言葉で文を分割したいと思っています。しかしどのように?ループ上の.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

split()を使用し、正規表現にこの文字列を割り当てると、分割する文字列が '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); 
    } 
} 
関連する問題