1
useDelimiter将无法识别垂直条,但会识别其他字符。useDelimiter将无法识别垂直条
这不起作用:
scan.useDelimiter("|");
这并不工作:
scan.useDelimiter(",");
休息代码:
Scanner scan = new Scanner("12,d, |, f | ");
// initialize the string delimiter
scan.useDelimiter(",");
// Printing the delimiter used
System.out.println("The delimiter use is "+scan.delimiter());
// Printing the tokenized Strings
while(scan.hasNext()){
System.out.print(scan.next());
}
// closing the scanner stream
scan.close();
或[pattern.quote(字符串或多个)](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote%28java.lang .String%29)。 – OldCurmudgeon
谢谢,就是这样。 – PixelPusher