useDelimiter将无法识别竖条

Pix*_*her 1 java delimiter

useDelimiter不会识别竖条,但会识别其他字符.

这不起作用:

scan.useDelimiter("|");
Run Code Online (Sandbox Code Playgroud)

这确实有效:

scan.useDelimiter(",");
Run Code Online (Sandbox Code Playgroud)

其余代码:

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();
Run Code Online (Sandbox Code Playgroud)

Tom*_*m C 5

您需要通过执行来逃避垂直条(管道角色);

scan.useDelimiter("\\|");
Run Code Online (Sandbox Code Playgroud)