| View previous topic :: View next topic |
| Author |
Message |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Tue May 01, 2007 5:29 am Post subject: split line |
|
|
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
So who can help me
Thanks |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue May 01, 2007 6:44 am Post subject: |
|
|
| 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 |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Tue May 01, 2007 7:10 am Post subject: |
|
|
Works, thanks
And if the line is someting like:
blabla bla bla -example rarara -example fdfsdfs |
|
| Back to top |
|
 |
|