Reputation: 67
Is there any way to print argument in a specific location? I tried to use the below command but each argument depend on the previous one.
puts [format "%0s%20s%30s%40s" $check $runtime $cpus $result]
That's mean if $check is long name all the other data will be shift accordingly. Is there any way to determine the specific location to puts the var?
Upvotes: 0
Views: 80
Reputation: 4813
You didn't indicate how you would like to resolve the situation when a string is too long to fit the allotted space. Assuming you want to cut off the tail of the string, you can specify a maximum length:
puts [format %-10.9s%-10.9s%-10.9s%-10.9s $check $runtime $cpus $result]
The - will anchor the strings to the left, 10 specifies the field width and 9 limits the number of characters printed.
Demo:
set check "longcheckname"
set runtime "forever"
set cpus "all"
set result "passed"
puts [format %-10.9s%-10.9s%-10.9s%-10.9s $check $runtime $cpus $result]
Result:
longcheck forever all passed
Upvotes: 1