Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a string which contains " "

Tags:

c#

I have a string from an xml document:

<title type="html">

Is there a way for me to write this string like "<title type="html">"? I've had similar problems writing javascript as a string but I did see some solutions in the past (which I can't remember)?

Thanks

like image 243
GurdeepS Avatar asked Jun 10 '09 10:06

GurdeepS


3 Answers

You need to escape your double quotes..

string blah = "<title type=\"html\">";

OR

string blah = @"<title type=""html"">";

Alternatively you could use single quotes in your tag, which will serve the same purpose.

string blah = "<title type='html'>"; 
like image 133
Eoin Campbell Avatar answered Oct 16 '22 16:10

Eoin Campbell


You can escape quotes in a string using a \

String s = "this is my \"data\" in the string";
like image 37
Simon P Stevens Avatar answered Oct 16 '22 15:10

Simon P Stevens


Escape:

var str = "<font color=\"red\">;";

(Edit: forgot to put proper html chars in!)

Or in javascript you can use single quotes to contain one with doubles:

var str = '<font color="red">';
like image 24
gub Avatar answered Oct 16 '22 15:10

gub