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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

padding a space in front of a string

Status
Not open for further replies.

snowingnow

Programmer
Jun 1, 2006
32
CA
How to padding a certain number of spaces in front of a string ? Thanks
 
set str [string repeat " " $num]
append str $otherString

_________________
Bob Rashkin
 
Neetend it up a bit...

proc string_pad {orig {num 1} {char " "} {side front} } {

# pad string on either side with a number of characters

set pad [string repeat $char $num]
switch $side {
beginning - front {return $pad$orig}
back - end {return $orig$pad}
default {return $orig}
}
}

set s "Hello World!"

set s [string_pad $s 20 { } front]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top