1

我正在尝试将文字字符串附加"\F\"到 StringBuilder 对象。我使用转义字符将替换字符串声明为字符串变量,如下所示:

String replace = "\\F\\";

当我将变量替换附加到我的 StringBuilder 对象时,我会在结果字符串中得到转义字符。例如:

StringBuilder builder = new StringBuilder("This is the string I will be appending to.");
String replace = "\\F\\";
builder.append(replace);
String newString = builder.toString();

newString 的结果值为"This is the string I will be appending to.\\F\\"。我希望 newString 的值为"This is the string I will be appending to.\F\"

在旁注中,当我执行

System.out.println(replace);

系统正确删除了"\F\"控制台上的转义字符。

如果在其他地方回答,请提前道歉。我进行了广泛的搜索,但没有找到我想要的东西。任何帮助将不胜感激。谢谢你。

4

0 回答 0