egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

split line

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Tue May 01, 2007 5:29 am    Post subject: split line Reply with quote

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?t=12042&highlight=regexp

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

Code:

set one $text
set two $text
regsub -all -- $one "-example*" one ""
regsub -all -- $two "*-example" two ""


But ofcourse that didnt worked Rolling Eyes

So who can help me
Thanks
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue May 01, 2007 6:44 am    Post subject: Reply with quote

Code:
regexp {(.*)\s-example\s(.*)} $line all one two

Edit: Or you can do it faster using this method:
Code:
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]]
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Tue May 01, 2007 7:10 am    Post subject: Reply with quote

Works, thanks

And if the line is someting like:

blabla bla bla -example rarara -example fdfsdfs
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber