# Hold the value of a variable

This is my code

xyzzy = 1;
Hold[xyzzy] // ToString // StringLength


The output is 11.

This 2nd one below.

ClearAll[xyzzy]
ToString[xyzzy] // StringLength]


The output is 5.

Why is this?

I think these 2 codes will be the same output

• the result of Hold[xyzzy] is Hold[xyzzy] and that is 11 characters long. When xyzzy has not been assigned any value then the ToString[xyzzy] will be the string xyzzy and that is 5 characters long. – Bill Sep 4 '20 at 2:24
• @Bill How can I fix this? How can make it have the same output? – kile Sep 4 '20 at 2:28
• What output is the desired? 5, 11, or 1? – xzczd Sep 4 '20 at 3:03
• Possibly HoldForm[xyzzy] // ToString // StringLength does what you want? – Carl Woll Sep 4 '20 at 4:16
• Hold[xyzzy] // ToString // StringLength[#] - 6 &? – kglr Sep 4 '20 at 5:54

StringLength["Hold[xyzzy]"]
StringLength["xyzzy"]