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.

split line

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

split line

Post by pipo »

I need some help splitting one line into two,
I have for example this line:

blabla bla bla -example rarara

I want the bot to announce it like this:
<bot> blabla bla bla
<bot> rarara

so everyting before "-example" will be announced on the first line and everyting after "-example" will be announced on the second line

I search true this forum and the only thing i could find that is almost the same as i am looking for was http://forum.egghelp.org/viewtopic.php? ... ght=regexp

Now i am really a noob, so laugh and make fun of me, but i tried:

Code: Select all

set one $text
set two $text
regsub -all -- $one "-example*" one ""
regsub -all -- $two "*-example" two ""
But ofcourse that didnt worked :roll:

So who can help me
Thanks
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

regexp {(.*)\s-example\s(.*)} $line all one two
Edit: Or you can do it faster using this method:

Code: Select all

if {[set i [lsearch -exact [split $line] -example]]!=-1} {
 set one [join [lrange [split $line] 0 [expr {$i-1}]]]
 set two [join [lrange [split $line] [expr {$i+1}] end]]
}
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

Works, thanks

And if the line is someting like:

blabla bla bla -example rarara -example fdfsdfs
Post Reply