【发布时间】:2012-02-17 08:42:41
【问题描述】:
我正在尝试逐字阅读输入,但不知道如何将扫描仪的分隔符设置为空格和标点符号,除了 '(单引号)。 这是我得到的
BufferedReader input;
String line;
Scanner sc;
String word;
try {
input = new BufferedReader(new FileReader(path));
while (input.ready()) {
line = input.readLine();
System.out.println("Current Line: " + line);
sc = new Scanner(line);
sc.useDelimiter("\\W\\s^\'");
//...
}
}
//...
【问题讨论】:
-
String line = sc.nextLine();String[] words = line.split(" "); -
@run 还有标点符号呢?
-
是的,我的代码与此类似。
-
@Qwe 你会得到所有的单词,包括
words数组中的标点符号,例如:it's great你会得到it's和great单词(在单词数组中),或者你想要 3像it、s、great这样的词。你能帮我澄清一下吗