void splitIntoWords(final String s) { BreakIterator wordBreaker = BreakIterator.getWordInstance(); wordBreaker.setText(s); int end = 0; for(int start = wordBreaker.first(); (end = wordBreaker.next()) != BreakIterator.DONE; start = end) { String word = s.substring(start, end); // word includes spaces String trimmedWord = word.trim(); // Do something with trimmedWord } }
Programming Tips - Java: split a string into English words?
Date: 2011may30
Language: Java
Q. Java: split a string into English words?
A. Use BreakIterator like this: