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
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityYour first code acts as below line:
StringLength["Hold[xyzzy]"]
And second one acts as below line:
StringLength["xyzzy"]
Hold[xyzzy]
isHold[xyzzy]
and that is 11 characters long. Whenxyzzy
has not been assigned any value then theToString[xyzzy]
will be the stringxyzzy
and that is 5 characters long. $\endgroup$5
,11
, or1
? $\endgroup$HoldForm[xyzzy] // ToString // StringLength
does what you want? $\endgroup$Hold[xyzzy] // ToString // StringLength[#] - 6 &
? $\endgroup$