-2

I try to create a unit test,

I have a code that produces the following string:

{<a class="btn btn-default" href="Page1">1</a><a class="btn btn-default btn.primary selected" href="Page2">2</a><a class="btn btn-default" href="Page3">3</a>}

(this is what visual studio debugger shows me.)

I try to compare it with const

  const string str = @"{<a class=""btn btn-default"" href=""Page1"">1</a>"
                           + @"<a class=""btn btn-default btn-primary selected"" href=""Page2"">2</a>"
                           + @"<a class=""btn btn-default"" href=""Page3"">3</a>}";

but I get (as I see in the debugger)

"{<a class=\"btn btn-default\" href=\"Page1\">1</a><a class=\"btn btn-default btn-primary selected\" href=\"Page2\">2</a><a class=\"btn btn-default\" href=\"Page3\">3</a>}"

how do I remove the extra slashes?

edit the problem was i had btn.default instead of btn-default

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
Nahum
  • 6,959
  • 12
  • 48
  • 69
  • Did you try printing it? They appear only at the debugger – William Barbosa Aug 14 '15 at 17:16
  • possible duplicate of [Can I escape a double quote in a verbatim string literal?](http://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal) – Nahum Aug 14 '15 at 17:20

3 Answers3

7

In the debugger click on the magnifying glass icon, and you will get the string without backslash.

In real there is no back slash, it is just a way of showing value in the debugger.

enter image description here

That is how it should appear:

enter image description here

Habib
  • 219,104
  • 29
  • 407
  • 436
  • In other words, the verbatim literal only applies in code. The debugger will display it as a regular string and not use the verbatim syntax. – Jeff Mercado Aug 14 '15 at 17:17
2

The slashes appear only on the debugger. If you try printing this string or using it elsewhere, you'll see they're not there

You see them in the debugger because this is how a string is composed in order for the \ character to appear. The @ verbatim is just a syntactic sugar that abstracts it for you.

William Barbosa
  • 4,936
  • 2
  • 19
  • 37
-1

OK. Seems this is a weird Visual studio behaviour

the slashes are added only when you hover a string.

when I hover a const string when I hover a const string

when I hover StringBuilder when I hover StringBuilder

Nahum
  • 6,959
  • 12
  • 48
  • 69
  • the StringBuilder.ToString() and the const string I have are equal. I excepted them to have same display in the debugger. the fact they don't is weird and confusing. – Nahum Aug 14 '15 at 17:31
  • No, it ain't. They're different classes. When using a StringBuilder, it means I'm constructing (possibly dinamically) a string. I probably want to see the string the way it will be displayed. But, well, that's a matter of opinion, really :) – William Barbosa Aug 14 '15 at 17:33