1

I've been trying to find a way to render \r\n as actual newlines in the immediate and command window in my VB.NET 4.5.1 application. I came across this question which teaches about the nq specifier, but it appears to apply only to C#. In VB.NET, nq doesn't even appear to work because I get Expression expected printed back out at me.

Is there a different way to make newlines actually show as separate lines in the immediate or command window in VB.NET?

Community
  • 1
  • 1
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
  • @leppie Why did you remove the VS 2013 tag? – oscilatingcretin Jun 22 '15 at 19:04
  • VB.NET does not support format specifiers. That's where that ends, use the Text Visualizer instead. Looks like a spy glass icon. – Hans Passant Jun 22 '15 at 19:09
  • 4
    VB will also print `\r\n` as `"\r\n"`. use `Environment.NewLine` – Ňɏssa Pøngjǣrdenlarp Jun 22 '15 at 19:11
  • @HansPassant I know of the spy glass icon when I want to use the text visualizer while debugging variable/property values, but I need this specifically for the command/immediate windows. I've check both and see no such icon. FYI, I created a helper method that is meant to be called only from the immediate/command windows. The return string may have newlines, so I need to capture those as well. – oscilatingcretin Jun 22 '15 at 19:14
  • 1
    FWIW, the output window converts like you want (`Console.WriteLine(...)`) – Ňɏssa Pøngjǣrdenlarp Jun 22 '15 at 19:50
  • Write your own sub() to convert the desired characters? – rheitzman Jun 22 '15 at 20:37
  • @Plutonix It's a webforms app, not a console app. I did try `Console.WriteLine()` thinking it might show up in the output window, but it just says `Expression does not produce a value.` – oscilatingcretin Jun 23 '15 at 13:54

2 Answers2

1

An easier way in visual studio 2015 is to do this in the debug window:

?string,nq

You can also do the debug version in earlier versions of VS

?System.Diagnostics.Debug.Print(string,nq)
user2728841
  • 1,333
  • 17
  • 32
0

I've discovered that the solution is to use System.Diagnostics.Debug.Print(). To reproduce the original issue, entering this into the Immediate window...

? "a" & vbCrLf & "a"

...just returns this:

"a a"

However, using this...

System.Diagnostics.Debug.Print("a" & vbCrLf & "a")

...actually shows the newline:

a
a
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206