立即窗口中的换行符

发布于 2024-09-01 20:14:46 字数 375 浏览 10 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

起风了 2024-09-08 20:14:46

其实是有办法的。您可以在立即窗口中使用格式说明符来更改显示格式。如果您有一个包含回车符和换行符的字符串 ("\r\n"),您可以在打印请求后使用“无引号”格式说明符。

在立即窗口中键入:

?MyObj.ToString(),nq

并且 \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:

?MyObj.ToString(),nq

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

栀子花开つ 2024-09-08 20:14:46

不幸的是没有。这里发生的事情是调试器 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文