Hi, I need a quick help.
ToString[001] returns 1 as a string (and not 001). How do I get a string with 0’s padded on the left to make it of a fixed size? In this example I want the output to be 001 (string form) instead of just 1. Someone please help.
Thanks.
Hello,
A somewhat quick and dirty way::
In[113]:= ToStringPad[n_, len_, pad_] := FromCharacterCode[ PadLeft[ToCharacterCode[ToString[n]], len, First[ToCharacterCode[pad]]]]; ToStringPad[1, 3, "0"] ToStringPad[22, 8, "="] Out[114]= "001" Out[115]= "======22"
IntegerString may be the function you are looking for.
IntegerString[1, 10, 3]