Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading