Jun 20, 2007 #1 snowingnow Programmer Joined Jun 1, 2006 Messages 32 Location CA How to padding a certain number of spaces in front of a string ? Thanks
Jun 20, 2007 #2 Bong Programmer Joined Dec 22, 1999 Messages 2,063 Location US set str [string repeat " " $num] append str $otherString _________________ Bob Rashkin Upvote 0 Downvote
Jun 23, 2007 #3 snowdork Programmer Joined Jun 23, 2007 Messages 1 Location US 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] Upvote 0 Downvote
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]