views:

60

answers:

6

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"
+1  A: 

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\"";
Oded
+6  A: 

So you are essentially asking how to store doublequotes within a string variable? Two solutions for that:

var string1 = @"""inside quotes""";
var string2 = "\"inside quotes\"";

In order to perhaps make it a bit more clear what happens:

var string1 = @"before ""inside"" after";
var string2 = "before \"inside\" after";
Fredrik Mörk
A: 

Put a backslash (\) before the double quotes. That should work.

Belinda
+1  A: 

You could use &quot; instead of ". It will be displayed correctly by the browser.

Jens
+1  A: 

If I understand your question properly, maybe you can try this:

string title = string.Format("<div>\"{0}\"</div>", "some text");
Dave
A: 
graham