我有一个类似于 C:\Users\temp\index.html
的字符串,并且希望将 "\"
替换为 "\\"
>。我尝试过以下方法:
str= str.replace("\", "\\");
..但是 Eclipse 一直建议我向替换方法添加参数。
如有任何帮助,我们将不胜感激。
最佳答案
您需要转义斜杠字符:
str = str.replace("\\", "\\\\");
关于java - 使用 String.replace() 替换斜杠即 "\",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10743497/