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
  • 13,382
  • 4
  • 33
  • 49
1

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

"<span class=\"icon phone\">m</span>"
MPelletier
  • 15,673
  • 14
  • 84
  • 131
1

How about

new XElement("span", new XAttribute("class", "icon phone"), "m").ToString()    
Colonel Panic
  • 126,394
  • 80
  • 383
  • 450
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
  • 4,949
  • 2
  • 39
  • 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,000
  • 6
  • 41
  • 52
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,943
  • 2
  • 13
  • 18
0

try this:

  string str="<span class=\"icon phone\">m</span>";
KF2
  • 9,421
  • 8
  • 39
  • 76