final String remove = " " // tab is 3 spaces
while (lineOfText != null)
{
if (lineOfText.contains(remove))
{
lineOfText = " ";
}
outputFile.println(lineOfText);
lineOfText = inputFile.readLine();
}
我尝试运行此程序,但它不会用一个空格替换选项卡。有什么办法吗?
最佳答案
制表符不是三个空格。这是您通过转义获得的特殊字符,特别是final String remove = "\t";
和
if (lineOfText.contains(remove))
lineOfText = lineOfText.replaceAll(remove, " ");
}
或删除
if
(因为replaceAll
不需要它),例如lineOfText = lineOfText.replaceAll(remove, " ");
关于java - 用空格替换选项卡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41453983/