立即窗口中的换行符
使用 Visual Studio 2010 Professional,我有一个 ToString()
方法,如下所示:
public override string ToString()
{
return "something" + "\n" + "something";
}
因为有几个“something
”并且每个都很长,所以我想 悲伤地看到
something
something
,我看到
"something\nsomething"
有没有办法得到我想要的东西?
Using Visual Studio 2010 Professional, I have a ToString()
method that looks like this:
public override string ToString()
{
return "something" + "\n" + "something";
}
Because there are several "something
"'s and each is long, I'd like to see
something
something
Sadly, I'm seeing
"something\nsomething"
Is there a way to get what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其实是有办法的。您可以在立即窗口中使用格式说明符来更改显示格式。如果您有一个包含回车符和换行符的字符串 (
"\r\n"
),您可以在打印请求后使用“无引号”格式说明符。在立即窗口中键入:
并且
\r\n
将在立即窗口中导致换行。有关格式说明符的更多信息,请参阅:
http://msdn.microsoft.com/en-us/library/e514eeby。 ASPX
Actually there is a way. You can use format specifiers in the immediate window to change the format of the display. If you have a string with carriage returns and linefeeds in it (
"\r\n"
) you can follow the print request with the 'no quotes' format specifier.In the immediate window type:
and the
\r\n
will cause newlines in the immediate window.For more info on format specifiers see:
http://msdn.microsoft.com/en-us/library/e514eeby.aspx
不幸的是没有。这里发生的事情是调试器 API 设计的产物。
负责处理
ToString()
调用的组件是表达式计算器。它是大多数调试器窗口(监视、本地、即时等)的数据源。对于除即时窗口之外的每个窗口,该值都显示在一行上。在单行上显示多行字符串没有多大意义。因此,表达式求值器通过将换行符转义为可显示的版本,使字符串更易于显示。
这种技术对于当地人和观察窗口来说非常有效。但在立即窗口中,显示多行值更有意义,但它的意义就小得多。不幸的是,表达式求值器不知道数据将显示的上下文,因此会执行转义换行符的安全操作。
Unfortunately no there is not. What's happening here is an artifact of the design of the debugger APIs.
The component responsible for processing the
ToString()
call is the expression evaluator. It's the data source for the majority of the debugger windows (watch, locals, immediate, etc ...).For every window but the immediate the value is displayed on a single line. Displaying a multiline string on a single line doesn't make much sense. Hence the expression evaluator makes the string slightly more displayable by escaping newline characters into a displayable version.
This technique works pretty well for the locals and watch window. But in the immediate window where it makes more sense to display the multiline value it makes a lot less sense. Unfortunately the expression evaluator doesn't know the context of where it's data will be displayed and hence does the safe operation which is to escape the newlines.