我有一个这样的字符串变量:
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"
当前回答
如果您还想向包含动态值的字符串添加双引号。同样,在CodeId[i]和CodeName[i]的地方,您可以放入动态值。
data = "Test ID=" + "\"" + CodeId[i] + "\"" + " Name=" + "\"" + CodeName[i] + "\"" + " Type=\"Test\";
其他回答
您还可以将双引号包含到单引号中。
string str = '"' + "How to add doublequotes" + '"';
一种间接的,但简单易懂的替代方法,在字符串的开头和结尾添加引号-
char quote = '"';
string modifiedString = quote + "Original String" + quote;
你可以用"而不是“。”浏览器将正确地显示它。
在c#中,你可以使用:
string1 = @"Your ""Text"" Here";
string2 = "Your \"Text\" Here";
使用工作示例的字符串插值:
var title = "Title between quotes";
var string1 = $@"<div>""{title}""</div>"; // Note the order of the $@
Console.WriteLine (string1);
输出
<div>"Title between quotes"</div>