Quotation mark in string

2019-01-28 05:12发布

问题:

I have some string with variable, e.g.

string path = @"C:\one\filename.exe" + arguments

arguments: "-s -c -d > "somedirectory\some file.txt""

I've problem with redirection output to "somedirectory\some file" If I put "\"" or char.ToString('"') it always interprets as \"...not alone "

How should I put this " character into arguments?

回答1:

You need to use \".

The debugger shows it as \", since it shows valid string literals.
However, the actual value in the string is ". (You can see this in the Text Visualizer)

In a verbatim string literal (@"..."), you need to use "" instead.



回答2:

var arguments =  @"-s -c -d > ""somedirectory\some file.txt""";

or

var arguments = "-s -c -d > \"somedirectory\\some file.txt\"";


回答3:

string args = @"-s -c -d > ""somedirectory\some file.txt"""

try that.

for more information, http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx