我有一个这样的字符串变量:
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"
当前回答
string doubleQuotedPath = string.Format(@"""{0}""",path);
其他回答
一种间接的,但简单易懂的替代方法,在字符串的开头和结尾添加引号-
char quote = '"';
string modifiedString = quote + "Original String" + quote;
你可以使用$。
插入字符串: 用于构造字符串。插值字符串看起来像包含插值表达式的模板字符串。插值后的字符串返回一个字符串,该字符串将其包含的插值表达式替换为它们的字符串表示形式。该特性在c# 6及更高版本中可用。
string commentor = $"<span class=\"fa fa-plus\" aria-hidden=\"true\"> {variable}</span>";
在c#中,你可以使用:
string1 = @"Your ""Text"" Here";
string2 = "Your \"Text\" Here";
在c# 11.0预览版中,你可以使用原始字符串字面值。
Raw string literals are a new format for string literals. Raw string literals can contain arbitrary text, including whitespace, new lines, embedded quotes, and other special characters without requiring escape sequences. A raw string literal starts with at least three double-quote (""") characters. It ends with the same number of double-quote characters. Typically, a raw string literal uses three double quotes on a single line to start the string, and three double quotes on a separate line to end the string.
string str = """
"How to add double quotes"
""";
<i class=\"fa fa-check-circle\"></i>"与Eval()数据绑定的三元运算符一起使用:
Text = '<%# Eval("bqtStatus").ToString()=="Verified" ?
Convert.ToString("<i class=\"fa fa-check-circle\"></i>") :
Convert.ToString("<i class=\"fa fa-info-circle\"></i>"