Visual Studio 2010: While debugging, how can I copy string values containing carriage returns out of variables?
carriage-return, copy-paste, debugging, visual-studio-2010, watch
Solution
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:
This opens the Text Visualiser from where you can copy/paste:
Problem
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.