如何在字符串变量中包含转义序列
我有一个带有名为“TestValue”的字符串属性的类型,其中包含一个字符串,其中包含作为 c# 转义序列的字符。例如“blah\”“。我也需要将这些字符打印到控制台。
Console.WriteLine(obj.TestValue);
// 仅打印 blah”
当我将鼠标悬停在调试器中的该变量上,我可以看到确切的字符串“blah\””,但是当打印到控制台时,仅显示 blah“,我想要 blah\”< /strong>
我怎样才能让它发挥作用?
I have a type with a string property called 'TestValue' that contains a string that includes characters that are escape sequences for c#. e.g. "blah\"". I need these characters to print out to the console as well.
Console.WriteLine(obj.TestValue);
// prints only blah"
When I hover over that variable in the debugger I can see the exact string "blah\"", but when printed out to the console, only blah" shows up, I want blah\" to show up.
How can I get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
选择一个:
@"blah\"""
或"blah\\\""
@
表示逐字字符串,但您仍然需要通过将其加倍来转义双引号,或者您可以通过将其加倍来转义\
。Choose one:
@"blah\"""
or"blah\\\""
@
denotes a verbatim string, but you still need to escape a double quote by doubling it up. Or you can simply escape the\
by doubling it.您可以在此页面中找到包含反斜杠和双引号的转义序列标记。因此,您必须使用反斜杠将它们转义,如下所示:
You can find in this page the escape sequences which include Backslash and Double quotation mark. So, you have to escape them both by a backslash like the following:
这可能会有所帮助:http://msdn。 microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx
This may be helpful: http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx
使用 \ 转义任何字符。因此,如果要打印 \ 字符,请使用
\\
use \ to escape any characters. so, if you want to print the \ character, use
\\