【发布时间】:2014-01-25 01:50:06
【问题描述】:
我正在尝试根据标点符号将一段文本拆分为单独的句子,即 [.?!] 但是,即使我指定了特定的,扫描仪也会在每个新行的末尾拆分行图案。我该如何解决这个问题?谢谢!
this is a text file. yes the
deliminator works
no it does not. why not?
Scanner scanner = new Scanner(fileInputStream);
scanner.useDelimiter("[.?!]");
while (scanner.hasNext()) {
line = scanner.next();
System.out.println(line);
}
【问题讨论】:
-
新行在您的代码中,因此它也在行尾分隔。从您的输入中删除新行。
标签: java regex java.util.scanner