How to add double quotes to a string that is inside a variable?

ANP picture ANP · Oct 11, 2010 · Viewed 548.9k times · Source

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 double quotes. So I have written something like:

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

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

"How to add double quotes"

Answer

Oded picture Oded · Oct 11, 2010

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\"";