如何向变量内的字符串添加双引号? [英] How can I add double quotes to a string that is inside a variable?
本文介绍了如何向变量内的字符串添加双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下变量:
string title = string.empty;
我的需要是,无论传递给它什么字符串,我都必须用双引号将内容显示在 div 中.所以我写了类似的东西:
My need is that whatever string is passed to it I have to display the content inside a div with in a double quotes. So I have written something like:
...
...
<div>"+ title +@"</div>
...
...
但是如何在此处添加双引号?这样它就会显示为:
But how can I add the double quotes here? So that it will display like:
"How to add double quotes"
推荐答案
您需要通过将它们加倍来转义它们(逐字字符串文字):
You need to escape them by doubling them (verbatim string literal):
string str = @"""How to add doublequotes""";
或者使用普通的字符串文字,你可以用 转义它们:
Or with a normal string literal you escape them with a :
string str = ""How to add doublequotes"";
这篇关于如何向变量内的字符串添加双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文