This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

padding with leading zero's

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

padding with leading zero's

Post by arfer »

I'm looking for a more elegant way of padding integer values with leading zero's please

I'm currently using

set color [string map {10 10 11 11 12 12 13 13 14 14 15 15 2 02 3 03 4 04 5 05 6 06 7 07 8 08 9 09} $value]

to create a two digit mirc color value from an input integer value of 2 through 15 such that I can then use it, for example, to format output text

\003$color$text\003

It works fine but I'm just not happy with it. Maybe I'm just too fussy

I suspect there must be a way to use the TCL format command but I'm not well versed in C from which format seems to derive it's syntax
t
tsukeh
Voice
Posts: 31
Joined: Thu Jan 20, 2005 6:22 am

Post by tsukeh »

Code: Select all

set color [format %02s $value]
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thank you. That looks much better. I thought as much
Post Reply