【问题标题】:How can I parse double quotes in this C# line? [duplicate]如何解析此 C# 行中的双引号? [复制]
【发布时间】:2021-02-08 04:51:25
【问题描述】:

我需要在此行中为路径字符串添加双引号:

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

我试过了

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

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

但它没有工作,我该怎么办?

【问题讨论】:

标签: c# double quotes


【解决方案1】:

删除 @ 符号以阻止反斜杠被视为文字字符而不是转义字符。然后 \" 可以用于双引号。

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

【讨论】:

  • 你能帮我解决这个问题吗? cmd.StartInfo.Arguments = "/C mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak("""+ Text +""")(window.close)") "
  • 有什么问题?您现在应该可以使用上面的信息来转义双引号。如果您想要其他字符的列表,这很有用 - csharpindepth.com/articles/Strings
【解决方案2】:

您不需要@-符号。您只需对双引号使用转义符号。做吧:

String Path = "The path string";
String s = "/C attrib -h -s -i \"" + Path + "\"";

【讨论】:

  • 你能帮我解决这个问题吗? cmd.StartInfo.Arguments = "/C mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak("""+ Text +""")(window.close)") ";
猜你喜欢
  • 2018-09-05
  • 1970-01-01
  • 1970-01-01
  • 2021-11-11
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
  • 1970-01-01
  • 2017-11-18
相关资源
最近更新 更多