Converting a sentence string to a string array of words in Java

后端 未结 16 2464
余生分开走
余生分开走 2020-12-01 00:04

I need my Java program to take a string like:

\"This is a sample sentence.\"

and turn it into a string array like:

{\"this\         


        
16条回答
  •  囚心锁ツ
    2020-12-01 00:28

    Try this:

    String[] stringArray = Pattern.compile("ian").split(
    "This is a sample sentence"
    .replaceAll("[^\\p{Alnum}]+", "") //this will remove all non alpha numeric chars
    );
    
    for (int j=0; i

提交回复
热议问题