我有一些带变量的字符串,例如
string path = @"C:\one\filename.exe" + arguments
arguments: "-s -c -d > "somedirectory\some file.txt""
我有重定向输出到"somedirectory\some file"
If I put的问题,"\""
或者char.ToString('"')
它总是解释为\"
...不是单独的"
我应该如何将这个"
角色放入参数中?
我有一些带变量的字符串,例如
string path = @"C:\one\filename.exe" + arguments
arguments: "-s -c -d > "somedirectory\some file.txt""
我有重定向输出到"somedirectory\some file"
If I put的问题,"\""
或者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