22

When I am stepping through code in c# (not sure if it's an issue in VB.NET) and looking at SQL stored in a string variable, sometimes I like to copy it and paste it into Notepad or my SQL program. If it contains carriage returns, though, it actually copies to my clipboard as line1\r\nline2. Is there a native method of copying this with actual carriage returns rather than carriage return escape codes?

Edit: This also applies to tabs which show as \t. This is happening because my code is reading SQL from a text file and the text file contains carriage returns and tabs. The alternative is to 1) not have any carriage returns or tabs in the SQL (which makes for ugly SQL) or 2) strip them out when reading the SQL into my string variable. I am not really keen to those options just for the sake of simplifying the debugging process, though.

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206

2 Answers2

49

It depends where you copy the value from.

If you hover your mouse over the variable when debugging, or look in the Locals window, you should see a little magnifying glass symbol in the tooltip.
Clicking this will open the Text Visualiser which should take account of any linebreaks.

For example, if my code is:

string test = "hello" + Environment.NewLine + "world";

Then I can look in Locals (notice it still shows \r\n there) or hover over test to see:

magnifying glass

This opens the Text Visualiser from where you can copy/paste:

enter image description here

Widor
  • 13,003
  • 7
  • 42
  • 64
  • Awesome. Your solution was perfect. I just copy the visualized text out of the window and it's good! – oscilatingcretin Jun 07 '12 at 14:39
  • I've been using Visual Studio for almost 20 years and had no idea this feature existed! A hearty thank you from 11 years in the future! – Moohasha Apr 25 '23 at 19:50
1

Put a breakpoint on the statment which has the variable (whole value you want to copy). As the control comes on the statement, move your mouse-pointer on the variable name. You will see a balloon box showing the variable name, a binocular icon and the value of the variable. Click on the binocular icon or the small down-arrow icon beside the binocular icon to view in it in text visualizer. Hope this is what you are looking at. This is in context with C# and hopefully its the same in VB.NET (but not sure).

Shant
  • 237
  • 1
  • 3
  • 16