Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用带引号的字符串?_C#_String_Double Quotes - Fatal编程技术网

C# 如何使用带引号的字符串?

C# 如何使用带引号的字符串?,c#,string,double-quotes,C#,String,Double Quotes,我有以下字符串,我希望将其作为进程执行: 运行dll32 Printui.dll,Printui条目/ia/K/q/m“SHARP MX-5500N PS”/h“Windows NT x86”/v 3/f sn0hMenu.inf 但是,考虑到引号的存在,我无法在C#中插入此字符串以使其编译,保留所有原始结构。我该如何解决这个问题?这有点棘手,因为字符串中有引号。您必须使用\转义引号。要使字符串显示为:Hello“World”您应该编写“Hello\“World\”您可以将@放在字符串定义的前面

我有以下字符串,我希望将其作为进程执行:

运行dll32 Printui.dll,Printui条目/ia/K/q/m“SHARP MX-5500N PS”/h“Windows NT x86”/v 3/f sn0hMenu.inf


但是,考虑到引号的存在,我无法在C#中插入此字符串以使其编译,保留所有原始结构。我该如何解决这个问题?这有点棘手,因为字符串中有引号。

您必须使用
\
转义引号。要使字符串显示为:
Hello“World”
您应该编写
“Hello\“World\”
您可以将@放在字符串定义的前面,并放置两个

string s = "Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m \"SHARP MX-5500N PS\" /h \"Windows NT x86\" /v 3 /f sn0hwenu.inf";
在本文中,您可以阅读有关字符串中转义字符的更多信息:


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

例如:

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

commit * -m "messBox.Text";

根据需要在引号前加上反斜杠:

string yourString = "This is where you put \"your\" string";

该字符串现在包含:
这是您放置“您的”字符串的地方

是的,这称为“转义”,通常在所讨论的字符前面加上反斜杠()。这可能重复回答您的问题吗?
gitInfo.Arguments = @"commit * " + "-m" + Convert.ToChar(34) + messBox.Text + Convert.ToChar(34);
commit * -m "messBox.Text";
string yourString = "This is where you put \"your\" string";