I'm trying to use escape characters to print a double quote. However, my program is throwing an error so I'm trying to debug it. When I add a watch to a string using an escape character it shows that the backslash is being included in the string literal. How do I use escape characters so that the \ doesn't become part of the literal?
You are confused by the debugger's behavior.
VS debugger will show the value with the escape character (Ex: 4\"
) in the Watch
section and on hovering but the code will properly use 4"
In the picture above, you can notice it's shown with the escape character by VS but displays correctly in the console.
following should work:
string fourInch = "4\"";
And it does in your example - the string is just shown with escape characters. If you click on the combobox at the end of the value-column and choose "Text" you can see that the correct format is saved...
The problem should be somewhere else in your code...