How do I convert integer to string with leading zeros in Tcl?

tcl
grokus picture grokus · Nov 5, 2009 · Viewed 13.8k times · Source

I'm learning Tcl. In Perl I can do this:

 $ perl -e 'for ($i = 0; $i < 5; $i++) { printf("name%03d\n", $i) }'
 name000
 name001
 name002
 name003
 name004

Can I do this in Tcl?

Answer

Sinan &#220;n&#252;r picture Sinan Ünür · Nov 5, 2009

See format:

$ tclsh
% for {set i 0} {$i < 5} {incr i} { puts [format "name%03d" $i] }
name000
name001
name002
name003
name004