I have a string from an xml document:
Is there a way for me to write this string like \"
You can also write it like this:
string f = @"<font color=""red"">";
Check out msdn on string literals.
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">';
If you're making a large string with a lot of XML, one approach would be to write
var str = @"<tag attribute=`value`><SubTag OtherAttribute=`OtherValue` /></tag>".Replace('`', '"');
Beware that this will be less efficient at runtime, because of the call to Replace().
The best way to handle this is might be to put the markup in a separate text file and embed it in a ResX file. That would allow you to write Properties.Resources.Markup
.
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'>";
string jason = "This string contains a \"";
You can escape quotes in a string using a \
String s = "this is my \"data\" in the string";