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.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Omg, I hate spoon feeding like this, but I guess I'm going to have to...

You have a general idea how long your longest string is, let's say its 20 characters in length... so we use format to padd each string with (20-length of string) [twenty minus length of string] spaces, by using the formatting option %-20s .... This way, all strings are columnized underneath eachother in a proper fashion.....

Code: Select all

set outfile [open "yourfile" w]
foreach {a b c d e} $yourlist {
  puts $outfile "[format %-20s%-20s%-20s%-20s%s $a $b $c $d $e]"
}
close $outfile
Other than this, I have no idea on how to make you comprehend.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i do understand what it is and what it does its

%s $a thats what your doing in a way your makeing colums

then you add

% -20%s like the with of the colum becomes 20 .. but its not exactly what i am looking for realy sorry if i am making you feel unconfortable .. don't mean to .. realy realy sorry hehe could be wrong but i think that is what you do
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 »

Code: Select all

proc bytesplit {nick uhost hand chan arg} {
  foreach line [split {[string bytelength $arg] > 100 && [string bytelength $arg]} < 120 \x20] {
      putserv "privmsg $chan :$line"
  }
}
more something like that but this doesn't work have to find the right syntax and way to put it ..
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 »

Ofloo wrote:

Code: Select all

proc bytesplit {nick uhost hand chan arg} {
  foreach line [split {[string bytelength $arg] > 100 && [string bytelength $arg]} < 120 \x20] {
      putserv "privmsg $chan :$line"
  }
}
more something like that but this doesn't work have to find the right syntax and way to put it ..
Are you trying to truncate your strings if they are too large? If this is the case, you should be using string range obviously.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

yes and no looks like it but not exactly would be same as
[lrange [split $arg {}] 0 100]
i got a description of somethig in db and that description is one line but some descriptions have byte count of 500 - 1000

and others have bytecounts of 1 - 20

in those descriptions are words with byte count 1 - 60 and i just wana output a deasend text but if you use the format thing then its like some workds are pressed to eachother sometimes don't even see the space and some are spread out that you have to go look for the second word .. so i want to a make a loop that splits the word on the first space after byte count 100 ..
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 »

ok got it used textutils (tcllib) to do so but if someone knows how to do it with out this plz post ;) tnx
XplaiN but think of me as stupid
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Check out string last (or first - depending on what you want) or string wordstart (or wordend). You should be able to make a word wrapping proc with one/more of these commands.
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i certainly will tnx
XplaiN but think of me as stupid
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

You might want to check this post. It's a word wrapping proc that splits the entire string and loops through the words. It doesn't split words that are too long to fit on a single line, though. But if you can live with that it should be just what you need. (I didn't do any speed tests to compare it to other methods of splitting because I'm too lazy right now, but it can't be that bad...it's fairly compact)
Have you ever read "The Manual"?
Locked