Dan Rayson
Dan Rayson

Reputation: 1417

How to get a String variable's value from VSCode's Watch window?

I can't quite believe I'm having to ask this, but how do I obtain the full value of a String variable in the Watch window in VSCode?

From here:

I want this string

I'm trying to get the multi-line string that I can see in the tooltip into my clipboard.

EDIT: If I expand out the treeview of values here in the Watch window, I can see deeper levels of the variable's object hierarchy. As suggested in ChatterOne's original answer, I could have copied the values from "primitive" types from the rght-clck context menu, however, this value is awkwardly a String type, so isn't working in the same way as primitives would. As shown here:

can't copy String

Note that only the lowest level (fullExceptionString.value[0]) has the copy value context menu item, but it's greyed out here, and I wanted the entire string not individual chars.

Upvotes: 4

Views: 7683

Answers (4)

Hoang
Hoang

Reputation: 177

I'm a bit late to this but you can try putting this in the variable watch

*(char (*)[3091])variableName

Upvotes: 1

sgryt
sgryt

Reputation: 290

Perhaps, you may copy/paste the output to any JSON formatter to work with your data.

In a debug console: copy(JSON.stringify(yourVarialbeHere));

I tope it helps.

Upvotes: 0

eiri
eiri

Reputation: 1

A workaround I found is to cast variable in Watch pane:
e.g. Type in "(char *)variableName" instead of "variableName".
It is annoying but works.

Upvotes: 0

ChatterOne
ChatterOne

Reputation: 3541

That's because you're selecting an expression with nested values.

If you right-click on anything "below" that (meaning in the same tree) but with a primitive value (meaning not nested), you'll see a copy value menu entry.

What you want is probably in the value entry. Expand that and right-click on the entry for which you need to copy the value.

Upvotes: 0

Related Questions