Java Reference
In-Depth Information
getLineInstance returns an iterator that shows where it is proper
to break a line in a string, for purposes such as wrapping text.
getSentenceInstance returns an iterator that shows where sentence
breaks occur in a string.
The following code prints each break shown by a given BreakIterator :
static void showBreaks(BreakIterator breaks, String str) {
breaks.setText(str);
int start = breaks.first();
int end = breaks.next();
while (end != BreakIterator.DONE) {
System.out.println(str.substring(start, end));
start = end;
end = breaks.next();
}
System.out.println(str.substring(start)); // the last
}
A BreakIterator is a different style of iterator from the usual
java.util.Iterator objects you have seen. It provides several methods
for iterating forward and backward within a string, looking for different
break positions.
You should always use these boundary classes when breaking up text
because the issues involved are subtle and widely varying. For example,
the logical characters used in these classes are not necessarily equival-
ent to a single char . Unicode characters can be combined, so it can take
more than one 16-bit Unicode value to constitute a logical character.
And word breaks are not necessarily spacessome languages do not even
use spaces.
Never speak more clearly than you think
Jeremey Bernstein
 
Search WWH ::




Custom Search