简体   繁体   中英

Search and Split the found Text

I'm trying to find a place from the input text and set the number after the = as a variable. Unfortunately, what is wrong output

With my code, the maxresults variable returns "i" as the result. But it should be 20.

Code:

bind pub "-|-" !a pub:a
proc pub:a { nick host handle channel text } {

    set maxresults ""
    if {[regexp -nocase {max=} $text]} {
    set maxresults0 [lindex [split $text max=] 1]
    set maxresults [lindex $maxresults0 0]
    putnow "PRIVMSG $channel :maxresults: $maxresults"
    }
}

Input: !a Remix find now country=german max=20 currency=euro

Output: maxresults: i

but it should be: maxresults: 20

You can do the whole job with regexp -

if {[regexp -nocase {max=(\d+)} $text - maxresults]} {
    putnow "PRIVMSG $channel :maxresults: $maxresults"
}

See the documentation at http://www.tcl-lang.org/man/tcl8.6/TclCmd/regexp.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM