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.

foreach usage question

Old posts that have not been replied to for several years.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

foreach usage question

Post by Ofloo »

how do i do this:

lets say u got a list of 100 args but i wana show new line for each 5 args if it was new line for each argument id use foreach line [split $arg] ..

but how do i do it when its like every 5 args ?

plz give me an example .. or something .
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Code: Select all

foreach {a b c d e} [split $arg] { .... }
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

so simple lol tnx verry mutch .. ;)
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm ok now i discoverd an other porblem, some words are long some are small if there is 5 small short words then u get result

a b c d e

but if the args are long then u get like

aqsdf bqsdf cqdsf dqsdf eqdf

my question how do i combine it with length ? So it doesn't look that messy..
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

See the tcl manpages for the "format" command.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

format ? explain how i should be using that to see if the length i know the man i read format again but i can't see what u mean maybe give an example so i can compare .. if u don't mind ..
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Hmm been reading looking on google but hmm still not sur what it is you mean could someone plz put me in the right direction ..?

i need to format text from one line into a nice layout so that the lines have kinda overal the same lenght ..

example how it should not look ..
a b c d
a_qsdf b_qsdf c_qsdf d_qsdf
a b_qsdf c d
a_qsdf b c_qsdf d_qsdf
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

For example,

Code: Select all

putlog "[format %-10s%-10s%-10s%s $a $b $c $d]"
Which you really should have figured out from the TCL Manpages, since you've been using TCL for quite a while now.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm it spreads nicely out in a channel but the thing is i wana write it nicely to a txt file so the text doesn't look like euhm

qq qqqqqqqqq qqqqqqqqqq qqqqqqqqq
qq qq q qq q
qqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqq qqqqqqqqqqqqq qqqqqqqqqq

if you know what i mean like that it would make nice formated text .. how would i do that ?? some words are longer then others so i wana split it on space but on a certain length .. and from what ive tested its not realy what i was looking for but tnx anyway you wouldn't know how to do that ?? do you .. hehe
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

You write to file formatted exactly like you write it to channel formatted. It isn't rocket science.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm i know but in the channel it adds spaces to spread it out .. but in txt those spaces are not there so ..

in channel
text_______text__textextextext
text________text_______________text
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Again, the spaces are there in the file if you format the text exactly how I showed you for the putlog formatting.... Why is this so hard for you to grasp?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

yes but its not exacty what i wanted to do isn't there a way to do byte count and split the space on a certain byte ?? so it doesn't spread out looks mutch nicer just don't have a clue how to begin on that ..
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Make up your mind, you either want to spread the data out evenly, or you don't.... If you do, use format, if you don't, don't use format. Simple as that...
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Sorry didn't mean to trouble u about it just want to have nice text format how its done who cares result counts but by spreading it out isn't realy working for me cause some strings contain realy big words and verry small ones so doesn't have a nice out put .. as i sad before its not realy what i am looking for but tnx for the help

.. :( sorry ..
XplaiN but think of me as stupid
Locked