字符串中的引号
我有一些带变量的字符串,例如
string path = @"C:\one\filename.exe" + arguments arguments: "-s -c -d > "somedirectory\some file.txt""
我有重定向输出到"somedirectory\some file"
如果我把"\""
或char.ToString('"')
它总是解释为\"
…不是唯一的"
我该如何将这个"
角色”加入争论?
你需要使用\"
。
调试器将其显示为\"
,因为它显示有效的字符串文字。
但是,字符串中的实际值是"
。(您可以在Text Visualizer中看到这一点)
在逐字字符串文字( @"..."
)中,您需要使用""
代替。
var arguments = @"-s -c -d > ""somedirectory\some file.txt""";
要么
var arguments = "-s -c -d > \"somedirectory\\some file.txt\"";
string args = @"-s -c -d > ""somedirectory\some file.txt"""
试试看。
有关更多信息,请访问http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx