Java 教程是为 JDK 8 编写的。本页中描述的示例和实践未利用在后续版本中引入的改进。
你可以使用 BreakIterator
来确定句子边界。首先使用 getSentenceInstance
方法创建 BreakIterator
:
BreakIterator sentenceIterator = BreakIterator.getSentenceInstance(currentLocale);
为了显示句子边界,程序使用 markBoundaries
方法,该方法在 Word Boundaries 部分中讨论。markBoundaries
方法在字符串下面打印插入符号(^)以指示边界位置。这里有些例子:
She stopped. She said, "Hello there," and then went on. ^ ^ ^ He's vanished! What will we do? It's up to us. ^ ^ ^ ^ Please add 1.5 liters to the tank. ^ ^