我有一个这样的字符串变量:
string title = string.empty;
我必须在双引号内的div中显示传递给它的任何内容。我写过这样的东西:
...
...
<div>"+ title +@"</div>
...
...
我怎么在这里加双引号?这样它就会像这样显示:
"How to add double quotes"
我有一个这样的字符串变量:
string title = string.empty;
我必须在双引号内的div中显示传递给它的任何内容。我写过这样的东西:
...
...
<div>"+ title +@"</div>
...
...
我怎么在这里加双引号?这样它就会像这样显示:
"How to add double quotes"
当前回答
如果你想在HTML中添加双引号
echo "<p>Congratulations, “" . $variable . "”!</p>";
输出
Congratulations, "Mr John"!
其他回答
您还可以将双引号包含到单引号中。
string str = '"' + "How to add doublequotes" + '"';
现在是c# 11
var string1 = """before "inside" after""";
var string2 = """ "How to add double quotes" """;
在c#中,你可以使用:
string1 = @"Your ""Text"" Here";
string2 = "Your \"Text\" Here";
使用
&dquo <div>&dquo"+ title +@"&dquo</div>
或者转义双引号:
\" <div>\""+ title +@"\"</div>
你需要通过将它们加倍来转义(逐字串字面量):
string str = @"""How to add doublequotes""";
或者对于普通的字符串,你可以用\:
string str = "\"How to add doublequotes\"";