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