Escape Characters Aren't Working In Debugger (C#)

别来无恙 提交于 2019-12-25 06:56:11

问题


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?


回答1:


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.




回答2:


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...



来源:https://stackoverflow.com/questions/31410576/escape-characters-arent-working-in-debugger-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!