egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

padding with leading zero's

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Thu Jan 03, 2008 11:11 am    Post subject: padding with leading zero's Reply with quote

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
View user's profile Send private message
tsukeh
Voice


Joined: 20 Jan 2005
Posts: 31

PostPosted: Thu Jan 03, 2008 11:54 am    Post subject: Reply with quote

Code:

set color [format %02s $value]
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Thu Jan 03, 2008 12:23 pm    Post subject: Reply with quote

Thank you. That looks much better. I thought as much
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber