-2

Ok so I've written code that will split a paragraph into sentences. Which is below. But now I want to split the sentences at the word "split". but how?

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]", "");
        }
}
Sean Wang
  • 778
  • 5
  • 14

1 Answers1

1

By using split() and assigning it your regex in this case the String you want it to split at which is'split'. Then we simply assign this to an String[] and loop over to print out all the contents.

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 );
    }
}
Tom C
  • 804
  • 2
  • 11
  • 24