This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

help with format

Old posts that have not been replied to for several years.
Locked
s
slashem
Voice
Posts: 18
Joined: Tue Aug 13, 2002 6:35 pm

help with format

Post by slashem »

searched this forum and see some ppl referring to the format command, but I'm having major problems with it on using it right :(

I need to notice the users the following line several times:
| date | user | item
but user can be different each time, so the layout gets all messed up like:
| date | user1 | item
| date | user152 | item

how can I properly align it? plz

Code: Select all

putserv "notice $nick : | [lindex $something 0] | [lindex $something $1] | [lindex $something 2]"   

is what I have now..
d
darko``
Op
Posts: 121
Joined: Sun Sep 08, 2002 5:33 pm
Location: Malta

Post by darko`` »

Either use a fixed width (9 chars or whatever is your nick or handle length) of pass trough every element of the list looking for the longest. Then use that for formating length. I am not aware of any other way to do that except to script it as i said.
Ignorant and lazy people will save 30 minutes by chosing simple config file. Smart ones will save 3000 minutes of *everyone's* time by opting for complete config file.
s
slashem
Voice
Posts: 18
Joined: Tue Aug 13, 2002 6:35 pm

Post by slashem »

ok, say I wanna use a fixed width of 10 chars..
how do I apply that format function to it so that "bobby" becomes "bobby "...
or do I have to make a procedure for usernames that adds spaces?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

OK - this is based on a single item, which has | at the start and end.

The list input will come from $nick, and the alignment is at 11 chars (IE, 10 chars between | and |).

Code: Select all

foreach a $nick {
  puts stdout "| ${a}[string repeat " " [expr 10 - [string length $a]]]|"
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Doing it with the format command is a lot easier.

Code: Select all

set str [format "| %10s | %10s | %10s" [lindex $baa 0] [lindex $baa 1] [lindex $baa 2]]
putserv "notice $nick :$str"
Look up the format command in the tcl manual for more info on controlling the output, but basically for what you want, you do %XXXs, which means "a string XXX chars wide".
Locked