Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy value of watch variable in visual studio without escape characters

Ok, this one has been driving me bonkers for ages and VS 2010 hasn't improved this. Say I have a variable like so

string szSql =  @"SELECT       Foo, Bar FROM      Table WHERE      Foo = Bar"; 

If I'm inspecting this in the debugger and choose "Copy Value" the value put into the clipboard has \r\n's in place of the carriage returns which is a bit of a pain. Is there a way to change this behaviour? (I know I can print it in the command window...)

Cheers,

Alex

like image 357
Fergal Moran Avatar asked Feb 24 '10 16:02

Fergal Moran


People also ask

How do I get the value of a variable in Visual Studio?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I add a variable to a watch in Visual Studio?

Right-click on a variable choose "Add Watch" in the context menu. Right-click on a variable in the DataTip and choose "Add Watch" "Add Watch" button from QuickWatch.

How do I use Quick Watch code in Visual Studio?

We open that window with the Shift + F9 key combination or with the 'QuickWatch' option from the right-click menu in the code editor. What 'QuickWatch' does is show us what the value of an expression or variable is at the current, paused state of the program.


2 Answers

Append ,nq (short for no quotes) to the variable name in the watch window and it will display the string without escape characters, which you could then copy. For reference the MSDN document is here.

like image 170
WhiteKnight Avatar answered Sep 20 '22 05:09

WhiteKnight


Use the "text visualizer" popup on the value and copy it to the clipboard from there. It will be unescaped.

like image 24
jlew Avatar answered Sep 22 '22 05:09

jlew