如何双引号添加到字符串,它是一个变量里面呢? [英] How to add doublequotes to a string that is inside a variable?

查看:402
本文介绍了如何双引号添加到字符串,它是一个变量里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的变量:

 串标题=的String.Empty;

我需要的是传递给它的任何字符串我有一个双引号。所以我写的东西像显示的div里面的内容:

  ...
...
< D​​IV>中+标题+ @< / DIV>
...
...

但如何在这里添加双引号?因此,它会显示如下:

 如何添加双引号


解决方案

您需要通过他们加倍逃避他们(逐字字符串):

 字符串str = @如何添加双引号

或用正常的字符串你逃避他们 \\

 字符串str =\\如何添加双引号\\;

I have variable like:

string title = string.empty;

My need is that whatever string is passed to it I have to display the content inside a div with in a doublequotes .So I have written something like:

...
...
<div>"+ title +@"</div>
...
...

But how to add the doublequotes here? So that it will display like :

"How to add doublequotes"

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆