-2

I need double quotes on this line for Path string:

cmd.StartInfo.Arguments = @"/C attrib -h -s -i "+ Path +" ";

I tried

cmd.StartInfo.Arguments = @"/C attrib -h -s -i "\""+ Path +""\" ";

and

cmd.StartInfo.Arguments = @"/C attrib -h -s -i "\"""+ Path +""\"" ";

but It didn't work, how can I do?

  • 2
    Does this answer your question? [Can I escape a double quote in a verbatim string literal?](https://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal) – devNull Oct 25 '20 at 20:46
  • 1
    One of several dozen good duplicate options: [Passing quotes in Process.Start arguments](https://stackoverflow.com/questions/13653991/passing-quotes-in-process-start-arguments). By the by, that is not 'parsing', but 'escaping' – Ňɏssa Pøngjǣrdenlarp Oct 25 '20 at 20:49

2 Answers2

0

Remove the @ symbol to stop the backslashes from being treated as literal characters rather than an escape character. Then \" can be used for the double quotes.

cmd.StartInfo.Arguments = "/C attrib -h -s -i \"" + Path + "\"";
ILally
  • 319
  • 1
  • 8
  • 13
  • can you help me also with this? cmd.StartInfo.Arguments = "/C mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak("""+ Text +""")(window.close)") " – Mauro Asganalovi Oct 26 '20 at 12:00
  • What's the issue? You should be able to escape double quotes now using the info above. If you want a list of other characters this is useful - https://csharpindepth.com/articles/Strings. – ILally Oct 26 '20 at 12:43
0

You don't need an @-symbol. You just have to use an escape symbol for the double quotes. Just do:

String Path = "The path string";
String s = "/C attrib -h -s -i \"" + Path + "\"";
SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
cryptic'l
  • 43
  • 5
  • can you help me also with this? cmd.StartInfo.Arguments = "/C mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak("""+ Text +""")(window.close)") "; – Mauro Asganalovi Oct 26 '20 at 11:31