簡體   English   中英

搜索並拆分找到的文本

[英]Search and Split the found Text

我試圖從輸入文本中找到一個位置,並將 = 后面的數字設置為變量。 不幸的是,有什么問題 output

使用我的代碼,maxresults 變量返回“i”作為結果。 但應該是20。

代碼:

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"
    }
}

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

Output:最大結果:我

但它應該是:最大結果:20

你可以用正則regexp完成整個工作 -

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

請參閱文檔http://www.tcl-lang.org/man/tcl8.6/TclCmd/regexp.htm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM