如何在里面使用带引号的字符串?

我有以下字符串,我想作为一个进程执行:

Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m "SHARP MX-5500N PS" /h "Windows NT x86" /v 3 /f sn0hwenu.inf

但是,如果存在引号,我无法在C#中插入此字符串以使其进行编译,从而保留所有原始结构。 我该怎么解决这个问题? 这有点棘手,因为字符串中有引号。

 string whatever = "Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m \"SHARP MX-5500N PS\" /h \"Windows NT x86\" /v 3 /f sn0hwenu.inf"; 

要么

 string whatever = @"Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m ""SHARP MX-5500N PS"" /h ""Windows NT x86"" /v 3 /f sn0hwenu.inf"; 

你可以把@放在字符串定义的前面并放两个"

 string myString = @"Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m ""SHARP MX-5500N PS"" /h ""Windows NT x86"" /v 3 /f sn0hwenu.inf" 

您可以在本文中阅读有关字符串中转义字符的更多信息:

http://www.yoda.arachsys.com/csharp/strings.html

 string s = "Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m \"SHARP MX-5500N PS\" /h \"Windows NT x86\" /v 3 /f sn0hwenu.inf"; 

你必须使用\转义引号。 有一个字符串说: Hello "World"你应该写"Hello\"World\""

您也可以始终使用Convert.ToChar(34),34是“的ASCII”。

例如:

 gitInfo.Arguments = @"commit * " + "-m" + Convert.ToChar(34) + messBox.Text + Convert.ToChar(34); 

等于:

 commit * -m "messBox.Text";