There is no error - you're verifying the string in the debugger, which automatically escapes strings - e.g. "Hello \ Goodbye"
will show in the debugger as "Hello \\ Goodbye"
.
That said, the debugger behaves differently depending on how you view a string (and also whether it's C#/VB of course):
- Hover over a string (most common) you'll get the escaped version in a tooltip
- Watch window/Locals etc also display escaped version
- If you select the 'Text' visualiser you'll see the unescaped version - which is what you should do to actually verify your string.
- Html visualiser does exactly what it says on the tin :)
Update
Okay, so I've gone a bit further and fired up VS2010, please create a test project and follow it through.
[TestMethod]
public void TestMethod1()
{
string a = @"`1234567890-=[]\ ;',./\~!@#$%^&*()_+{}|:""<>?|";
Console.WriteLine("Original:");
Console.WriteLine("{0}", a);
string htmlEncoded = System.Web.HttpUtility.HtmlEncode(a);
Console.WriteLine("Html Encoded:");
Console.WriteLine("{0}", htmlEncoded);
}
(obviously I've used a verbatim string initially to avoid having to escape anything except the double quote).
Console output of the test is:
Original:
`1234567890-=[]\ ;',./\~!@#$%^&*()_+{}|:"<>?|
Html Encoded:
`1234567890-=[]\ ;',./\~!@#$%^&*()_+{}|:"<>?|
Equally if you breakpoint the end of the test and start mucking about with the visualisers:
Hover (a
):
"`1234567890-=[]\\ ;',./\\~!@#$%^&*()_+{}|:\"<>?|"
i.e. it's C# escaped in the tooltip and surrounded by quotes.
Hover (htmlEncoded
):
"`1234567890-=[]\\ ;',./\\~!@#$%^&*()_+{}|:"<>?|"
.. again, it's html encoded and C# escaped with quotes
Text (htmlEncoded
):
`1234567890-=[]\ ;',./\~!@#$%^&*()_+{}|:"<>?|
.. No c# escaping
Html (htmlEncoded
):
`1234567890-=[]\ ;',./\~!@#$%^&*()_+{}|:"<>?|
In Times New Roman script of course :)
Which I believe takes us back to the original string - which also shows that the scenario you're describing can't be the case - unless you have read an escaped string as being "correct", when in fact it's not. Html doesn't require \
to be escaped.