写一个包含""的字符串

Gur*_*epS 5 c#

我有一个来自xml文档的字符串:

<title type="html">
Run Code Online (Sandbox Code Playgroud)

有没有办法让我写这个字符串像"<title type="html">"?我在将javascript写成字符串时遇到了类似的问题,但我确实在过去看到了一些解决方案(我记不住了)?

谢谢

Eoi*_*ell 27

你需要逃避双引号..

string blah = "<title type=\"html\">";

OR

string blah = @"<title type=""html"">";
Run Code Online (Sandbox Code Playgroud)

或者,您可以在标记中使用单引号,这将用于相同的目的.

string blah = "<title type='html'>"; 
Run Code Online (Sandbox Code Playgroud)


Sim*_*ens 21

您可以使用\来转义字符串中的引号

String s = "this is my \"data\" in the string";
Run Code Online (Sandbox Code Playgroud)