Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double quotes inside string HTML [duplicate]

Tags:

string

c#

I want to store this:

<span class="icon phone">m</span>

in a string. How do I do this?

Tried: @"<span class="+"icon phone"+">m</span>";

Tried: @"<span class="+@"icon phone"+">m</span>";

Please help!

like image 661
Coder Avatar asked Apr 25 '13 19:04

Coder


3 Answers

use single quotes, instead.

var html = "<span class='icon phone'>m</span>";

or double the quotes in a literal string

var html = @"<span class=""icon phone"">m</span>";

or escape the quote characters with the backslash character

var html = "<span class=\"icon phone\">m</span>";
like image 83
Mike Corcoran Avatar answered Sep 20 '22 03:09

Mike Corcoran


You can also omit the @ and escape the double quote with a backslash \:

"<span class=\"icon phone\">m</span>"
like image 25
MPelletier Avatar answered Sep 21 '22 03:09

MPelletier


How about

new XElement("span", new XAttribute("class", "icon phone"), "m").ToString()    
like image 23
Colonel Panic Avatar answered Sep 18 '22 03:09

Colonel Panic