字符串双引号在c#中替换为空

Jam*_*123 3 c# asp.net string

我有字符串.

There are no items to show in this view of the "Personal Documents"
Run Code Online (Sandbox Code Playgroud)

然后分配给字符串str变量

string str ="There are no items to show in this view 
of the \"Personal Documents\" library"
Run Code Online (Sandbox Code Playgroud)

现在计划替换"\"并使其成为实际的字符串到str对象.我试过下面,但没有奏效

str = str.Replace(@"\",string.Empty);
Run Code Online (Sandbox Code Playgroud)

我想要str值应该是

string str ="There are no items to show in this view 
of the "Personal Documents" library"
Run Code Online (Sandbox Code Playgroud)

我需要在另一个字符串中找到这个字符串.在搜索该字符串时.我找不到因为str包含"\".

dtb*_*dtb 13

表达字符串

There are no items to show in this view of the "Personal Documents"

在C#中,您需要转义该"字符,因为"在C#中使用它来包含字符串文字.

有两种选择:

请注意,在这两种情况下,"角色都会被转义.

在这两种情况下,str变量都包含相同的字符串.例如,

Console.WriteLine(str);
Run Code Online (Sandbox Code Playgroud)

版画

There are no items to show in this view of the "Personal Documents"

另请参见:字符串(MSDN)


编辑:如果你有字符串

There are no items to show in this view of the "Personal Documents"

并想进入

There are no items to show in this view of the Personal Documents

您可以像这样使用String.Replace方法:

string str = "There are no items to show in this view of the \"Personal Documents\"";

string result = str.Replace("\"", "");
Run Code Online (Sandbox Code Playgroud)

"\""表示由单个字符组成的字符串"(同样,在此常规字符串文字中转义),并且""是空字符串.