1
我试图捕获命令'\'可用于扩展命令到多行。因此,一个可能的分隔符可以是:Java扫描仪获取下一个分隔符
Pattern assignment = Pattern.compile("[^\\\\]\\n");
当然,这有“\ n”之前斩去最后一个非“\”字符的问题。我尝试通过以下尝试恢复该字符:
由于扫描器的输入形式为:T1 D1 T2 D2 T3 D3 ....其中T#和D#对应于令牌和分隔符号码'分别#”,我认为这会工作:
Pattern p = Pattern.compile("\\\\?\\s+");
String residue = file.findInLine(assignment);
String curToken = file.next().trim();
if(residue == null)
residue = "";
else
residue = residue.trim();
Scanner tokens = new Scanner(curToken + residue).useDelimiter(p);
非但没有T1和D1,findInLine,这是应该忽略扫描仪的分隔符的级联,当模式是一样的分隔符返回null!任何人都能解释这种奇怪的行为吗