Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String padding in Tcl

Status
Not open for further replies.

anirban2k2001

Programmer
Aug 25, 2003
27
0
0
IN
Hello everyone,


I need to write some fixed length data to a text file. I have a
variable named val whose value needs to be of a fixed length, say 7
characters. How do I pad the val variable with leading zero's so that
the length of the value stored in the variable is 7.


Example:


set rdg $val
where val contains '123'


I need to pad val so that it looks like '0000123'
Hope I have made myself clear.


Regards,
Anirban Sarkar.
 
Assuming the value is an integer, use
format %07i $val or
set val [format %07i $val]

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top