Copy value of watch variable in visual studio without escape characters - visual-studio

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

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.

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

For lengthy text, such as a large xml document, I always use the immediate window. Just type this in and hit enter:
System.Diagnostics.Debug.WriteLine(szSql)
and it will spit out the text with line breaks and without escape characters. I then copy from the immediate window.

Related

Is there a way to copy unescaped text variable values in VSC?

What I want is so simple. In Visual Studio Code, I want to copy the value of a text variable from the Watch window into memory.
I understand that, in the watch window, the text is escaped to put everything on one line. In other words,
Hello
world
is displayed as Hello\nworld in the Watch window. That makes sense.
But when I right-click on a string variable in the Watch window and select "Copy Value", I expect the copied value to be
Hello
world
not
'Hello\nworld'
Is there a way to do this in VSC (without the tedious need to search and replace for escape characters)?
(If you're as stumped as me, Upvote in solidarity.)
Old question but here goes:
This may depend on which debugger you are using, the below works in node/JavaScript.
Go to the Debug Console tab, and type the var name or expression at the prompt.
The debugger outputs the value, and you can select and copy it from there.

Visual studio Paste without moving cursor to the end

Is it possible to paste some string in visual studio via some shortcut or other extension to keep the cursor where it is after the paste?
This way if I add multiple words of string I will not have to go with the cursor back to the location via ctrl-arrows or home key when I don't want the cursor to go to the end of pasted text.
I actually found a way to do it with resharper - if any better suggestions out there please feel free to answer.
Create a simple template as
$END$$CopiedContent$
and set the CopiedContent variable to clipboard content. Give it a shortcut vc (ctrl-v inverted) - and have fun. It will require an extra left arrow and escape char to get desired effect.
It costs VC[TAB][Left_ARROW][ESCAPE] meaning 5 characters which is more than I originally wanted. Willing to trade for a better answer.

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

In vs2008 when using the debugger and copying a string's current value, automatically change \\ to \

In vs2008 when using the debugger and copying a string's current value, automatically change
\\
to
\
I end up having to debug long paths and always get things like
"e:\\eeeee\\blah\\d\\ddd\\fff\\bbbb\\rrrrr\\rrss\\sssss\\somefile.exe"
I then I have to go manually replace every doubleslash. Is there a quick dumb way so the variable gets put on the clipboard the way it would look on the screen?
Look at the far right of the box, there's a spy glass icon there. Click it.
That's the Text Visualizer. It displays the string the way it would appear if you wrote it to, say, the console. With the escapes applied and \r\n actually breaking the string into the next line. Copy and paste from that.
Did you try working with C# verbatim strings ? i.e. - #"string with \ backslash"?

Escaping period in Visual Studio Find Immediate Window

I learned about entering into the immeidate window >of filename trick in visual studio, but when I enter a period, which is reserved for separating menu items, it populates some junk that is irrelevant to what I want. For example, if I type >of web.config, and as soon as I get to the period (4th character) it would populate junk into the box.
Does anyone know how to escape it?
If you want to enter "." without auto-complete being activated hit escape then enter ".", auto-complete will kick back in and you don't have to worry about inadvertently completing the wrong file name.

Resources