| View previous topic :: View next topic |
| Author |
Message |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Jan 03, 2008 11:11 am Post subject: padding with leading zero's |
|
|
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 |
|
| Back to top |
|
 |
tsukeh Voice
Joined: 20 Jan 2005 Posts: 31
|
Posted: Thu Jan 03, 2008 11:54 am Post subject: |
|
|
| Code: |
set color [format %02s $value]
|
|
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Jan 03, 2008 12:23 pm Post subject: |
|
|
| Thank you. That looks much better. I thought as much |
|
| Back to top |
|
 |
|