oscilatingcretin
oscilatingcretin

Reputation: 10919

Visual Studio 2010: While debugging, how can I copy string values containing carriage returns out of variables?

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.

Upvotes: 22

Views: 10119

Answers (2)

Widor
Widor

Reputation: 13275

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

Upvotes: 50

Shant
Shant

Reputation: 237

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).

Upvotes: 1

Related Questions