If there is a paragraph in English, such as: I am a student. My name is AAA. I like to swim, play basketball and play football. There are commas, little numbers, or other symbols (but if you encounter single quotes, such as my father ' s In the Father ' s to be alone as a word, how can you separate each word separately.
I wrote you a small example. ~ ~
//key is the use of regular expressions public
class Stringtestone {public
static void Main (string[] args) {
String tags = "[, \\.\\s;!?] + ";//the Mark to be divided includes commas, periods, whitespace, exclamation marks, question mark ... You can add complete
String line = "I am a student." My name is AAA. I like? Yes I am sure! " +
"to swim, play basketball and play football." My father ' s football! ';
String [] re = line.split (tags);//split sentence according to given split tag ~ ~ for
(int i = 0; i < re.length i + +) {
System.out.println (i + 1) + ":" + re[i]);
}} Out put:
1:i
2:am
3:a
4:student
5:my
6:name 7:is 8:aaa
10:like
11:yes
12:i
13:am 14:sure 15:to 16:swim 17:play
18: Basketball
19:and
20:play
21:football
22:my 23:father
' s
24:football