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.

Cut string in pieces

Old posts that have not been replied to for several years.
Locked
t
tebor
Voice
Posts: 8
Joined: Sun Sep 12, 2004 1:27 am

Cut string in pieces

Post by tebor »

Hi Community!

Ok following problem...Long piece of text, in excess of 1000 chars, that has to be posted to a channel/nick.
Hence I cant post more then...400whatnot chars in one post I have to cut this long piece appart.
By the way the text comes from a mysql DB.

Can someone give me a nudge into the right direction as to how I take a string...and...lets say find out if there is a blankspace between char 380 and 400 and cut the string there and post it...take the rest of the string and do the same till stringlength is below 380 chars ?

Sincerely and greatfull for your help
Tebor
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

since sending text to an IRC user always breaks on line breaks, you'll probably need to split your text using the newline character as separator:

Code: Select all

foreach line [split $yourtext \n] {
  puthelp "notice $nick :$line"
}
t
tebor
Voice
Posts: 8
Joined: Sun Sep 12, 2004 1:27 am

Post by tebor »

No it actually doesnt...I have text that do not contain a \n for like pages.

see it as a variable containing a couple of hundred of chars that comes back from the mysqlDB

So how would I go about it to split it a blankspace beteern char 380 and 400 ?

demond wrote:since sending text to an IRC user always breaks on line breaks, you'll probably need to split your text using the newline character as separator:

Code: Select all

foreach line [split $yourtext \n] {
  puthelp "notice $nick :$line"
}
t
tebor
Voice
Posts: 8
Joined: Sun Sep 12, 2004 1:27 am

Re: Cut string in pieces

Post by tebor »

Maybe I can make it a bit clearer....

I am thinking along the lines of....

go thou string starting from char. 380 till you find first blankspace
take everything from 0 ->number of the blackspace and post it
then continue to then next +380chars and do the same
till the rest of the string is smaller then 380 of course.

Does that make any sense?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

dumping stuff that is not formatted (no line breaks) text to a person on IRC seems completely pointless to me but anyway:

Code: Select all

set n 380
while {[string length $stuff]} {
  set stuff [string replace $stuff 0 $n]
  puthelp "notice $nick :[string range $stuff 0 $n]"
}
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

you need to wrap words ?

this works wrote it while back maybe you get some ideas

http://ftp.ofloo.net/pub/scripts/wrap.tcl.gz

can be improved a bit by using lappend value $var instead of append value ${var}\x20

...
XplaiN but think of me as stupid
t
tebor
Voice
Posts: 8
Joined: Sun Sep 12, 2004 1:27 am

Post by tebor »

Woah so cool!

That is bloody briliant *grins*

Thank you that is going to be most valuable.



Ofloo wrote:you need to wrap words ?

this works wrote it while back maybe you get some ideas

http://ftp.ofloo.net/pub/scripts/wrap.tcl.gz

can be improved a bit by using lappend value $var instead of append value ${var}\x20

...
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

% set a bah
bah
% lappend a ohh
bah ohh
% append a hmmm
bah ohhhmmm
% lappend a crap
bah ohhhmmm crap
%
well see what i mean maybe can be improved a bit by using lappend instead of append .. don't need \x20 = which represents a space ..
XplaiN but think of me as stupid
Locked