I have been given a text from inputstream and first I put it into String via StringBuilder. Then I want to split the text(now string,since it's not from inputstream) in words, but in some places in the text there are not just one space, but more spaces between the words and interpunct symbols. Programming language should be JAVA.
Asked
Active
Viewed 1,277 times
1 Answers
0
A simple solution would be using the String split method:
String[] words = myString.split(" ");
If you have a StringBuilder instead of a String:
String[] words = myStringBuilder.toString().split(" ");
If you would like to split by any whitespace characters, use How do I split a string with any whitespace chars as delimiters?
myString.split("\\s+");

Community
- 1
- 1

Vineet Kosaraju
- 5,572
- 2
- 19
- 21