文档

Java™ 教程-Java Tutorials 中文版
句子边界
Trail: Internationalization
Lesson: Working with Text
Section: Detecting Text Boundaries

句子边界

你可以使用 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.
^                                 ^

Previous page: Word Boundaries
Next page: Line Boundaries