6

If I evaluate something in Immediate that produces a long and complex string, the debugger encodes everything in C string escapes, so I end up with a mess of \n, \t, and so on throughout my text which I then have to fix by hand. (Which is particularly annoying in the case of \n, as most text editors can't do multiline search-and-replace!)

Is there any way to get the debugger to give me the raw, un-munged, multi-line string value?

1
  • @ Mason Wheeler, any update? Would you please share the latest information about this issue?:)
    – Jack Zhai
    Commented Jan 11, 2017 at 9:18

4 Answers 4

3

We could check the string value with Text Visualizer in Watch window, which will show the string value without any \n and \t content.

Please add a breakpoint in the string variable in your code and start debugging your code. When the breakpoint hit, you could right-click the variable and choose "Add Watch" Then press F11 to go to next line of code. Now you could view the string value from Watch window by click the "Text Visualizer" icon. It will not show the \n and \t.

enter image description here

1
  • 2
    well, that is another way to look at it, but that is not the answer of the original question. Not every time you can use text visualizer, for example, ?SomeMethod() which products a string result with XML or so in multiple lines can not be used that way unless you hold the result in some variable and then use text visualizer. Commented Aug 18, 2017 at 10:26
1

You can use C# Interactive Window (Views > Other Windows > C# Interactive).

Usage:

Type command:

Console.Write("r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2\nr1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2")

Then I'll get:

r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2
r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2

C# Interactive Window is independent from the project so it will work on all projects of all language (C#, C++,...)

Here is the demo image:

CSharpInteractive.JPG

1

Set a format specifier at the end of the expression in the immediate window.

Problem:

? "test string with escape chars \r\nThis is on the next line"
"test string with escape chars \r\nThis is on the next line"

Add the , nq format specifier to the end:

? "test string with escape chars \r\nThis is on the next line", nq
test string with escape chars 
This is on the next line

This works exactly the same with a real variable:

? testvariable, nq
test string with escape chars 
This is on the next line

(I tried the answer from Konstantine Kozachuck using a format specifier on the Print statement and it did not work the same way the ? statement did, but it did help me figure out want I wanted.)

0

Print variableName,sb. Example (Immediate window):

>"raw\nmultiline\tstring",sb
raw
multiline   string

Documentation: https://learn.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp?view=vs-2019

Not the answer you're looking for? Browse other questions tagged or ask your own question.