5

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!

Coder
  • 83
  • 1
  • 2
  • 8

7 Answers7

7

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>";
Mike Corcoran
  • 14,072
  • 4
  • 37
  • 49
2

How about

new XElement("span", new XAttribute("class", "icon phone"), "m").ToString()    
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
1

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

"<span class=\"icon phone\">m</span>"
MPelletier
  • 16,256
  • 15
  • 86
  • 137
0

You can do so by typing " twice. It will appear once, inside a @-string.

So, in your case, to store:

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

Your string would be:

string s = @"<span class=""icon phone"">m</span>";
Luis Miguel Serrano
  • 5,029
  • 2
  • 41
  • 41
0

To save a quotes in a string, you have to mask it:

You can mask either by string mystring = @"<span class=""icon phone"">m</span>"; or by masking the quotes directly with a backslash (\) string mystring = "<span class=\"icon phone\">m</span>";.

jAC
  • 5,195
  • 6
  • 40
  • 55
0

Simply

String html = "<span class=\"icon phone\">m</span>"

Or you can use a String literal:

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

that's it.

Kai
  • 1,953
  • 2
  • 13
  • 18
0

try this:

  string str="<span class=\"icon phone\">m</span>";
KF2
  • 9,887
  • 8
  • 44
  • 77