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
Your 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. Whenxyzzyhas not been assigned any value then theToString[xyzzy]will be the stringxyzzyand that is 5 characters long. – Bill Sep 04 '20 at 02:245,11, or1? – xzczd Sep 04 '20 at 03:03HoldForm[xyzzy] // ToString // StringLengthdoes what you want? – Carl Woll Sep 04 '20 at 04:16Hold[xyzzy] // ToString // StringLength[#] - 6 &? – kglr Sep 04 '20 at 05:54Hold[xyzzy] // ReplaceAll[ Hold[a_] :> StringLength@ ToString[Unevaluated@a]]? – kglr Sep 04 '20 at 05:55Hold[xyzzy] and that is 11 characters long.How can you draw such a conclusion? – kile Sep 06 '20 at 01:15Hold[xyzzy] // ToStringis"Hold[xyzzy]", and it's obviously 11 characters long. – xzczd Sep 06 '20 at 02:43'Hold[]'in"Hold[xyzzy]"is counted? – kile Sep 06 '20 at 05:12"". – xzczd Sep 06 '20 at 05:17