| View previous topic :: View next topic |
| Author |
Message |
err0r Voice
Joined: 21 Apr 2012 Posts: 6
|
Posted: Sat Apr 21, 2012 9:06 pm Post subject: extracting information from text to variables |
|
|
i have this text :
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
i would like to capture the nickname, in this case its zet^
also the ident which in this case is CHAT2ME.c
the isp which is 41-135-29-27.dsl.mweb.co.za in the example
and finally : 41.135.29.27 which is wrapped between [ ]
any help would be usefull, i understand i need lindex
thanks Err0r |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Apr 22, 2012 2:44 am Post subject: Re: extracting information from text to variables |
|
|
| err0r wrote: | i have this text :
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
i would like to capture the nickname, in this case its zet^
also the ident which in this case is CHAT2ME.c
the isp which is 41-135-29-27.dsl.mweb.co.za in the example
and finally : 41.135.29.27 which is wrapped between [ ]
any help would be usefull, i understand i need lindex
|
| Code: |
bind pub - "!capture" captureit
proc captureit {nick uhost handle chan text} {
set nname [lindex [split $text] 1]
putserv "privmsg $chan :nname is: $nname"
set temp [lindex [split $text] 2]
set temp [string trimleft $temp ~(]
set ident [lindex [split $temp @] 0]
putserv "privmsg $chan :ident is: $ident"
set isp [lindex [split $temp @] 1]
set isp [string trimright $isp ,]
putserv "privmsg $chan :isp is: $isp"
set ip [lindex [split $text] 4]
set ip [string trim $ip \[\]]
putserv "privmsg $chan :ip is: $ip"
}
|
This could be condensed.
Do this in the channel with your bot:
| Code: |
!capture CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
|
and it will respond with the data in the manner you described.
I'm not sure what you are doing with it, but I hope this is enough of an example to get you going.
Reference :
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm |
|
| Back to top |
|
 |
err0r Voice
Joined: 21 Apr 2012 Posts: 6
|
Posted: Mon Apr 30, 2012 7:43 pm Post subject: Re: extracting information from text to variables |
|
|
| Not what i really wanted, but it has given me all i needed to get it going, many thanks willyw |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue May 01, 2012 1:08 am Post subject: |
|
|
Here is a simple method to get the same thing:
| Code: |
set text [split $text]
set nickname [lindex $text 1]
scan [string trim [lindex $text 2] {(),}] {%[^@]@%s} ident isp
set ip [string trim [lindex $text 4] {[]}]
|
where $text is the:
| Quote: |
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|