我正在使用Visual c# 2010编写一段生成字符串的代码。这个字符串需要包含反斜杠\和引号"。
我尝试过以下几种方法:
string StringOutputVariable;
string StringVariable = "hello world";
StringOutputVariable = "\"C:\\Program Files\\some program\\some program.exe\" " + StringVariable;
并且
string StringOutputVariable;
string StringVariable = "hello world";
StringOutputVariable = @"""C:\Program Files\some program\some program.exe"" " + StringVariable;
然而,它们都将转义字符放入输出字符串中:
\"C:\\Program Files\\some program\\some program.exe\" hello world
和
\"C:\\Program Files\\some program\\some program.exe\" hello world
我想要的输出是:
"C:\Program Files\some program\some program.exe" hello world
为什么我的代码会将转义字符输出到字符串中?
谢谢 Graham