This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Help for those learning Tcl or writing their own scripts.
daigo
Voice
Posts: 37 Joined: Fri Jun 27, 2014 8:02 pm
Post
by daigo » Sat Jul 26, 2014 1:56 pm
I want a wild card to be restricted to numbers only. How do I make the * and/or ? wildcards to be only numerical?
Get_A_Fix
Master
Posts: 206 Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand
Post
by Get_A_Fix » Sat Jul 26, 2014 2:10 pm
Something like
Code: Select all
proc isnum {string} {
if {[regexp {^-?\d+(\.\d+)?$} $string]} {
return 1;
}
return 0;
}
then you are able to make if statements, like..
Code: Select all
if {![isnum $arg]} {puthelp "PRIVMSG $chan :You did not type a number"; return}
if {[isnum $arg]} {puthelp "PRIVMSG $chan :You did type a number"; return}
for more wildcarding, you'd use a string match.
Code: Select all
if {[isnum $arg] && [string match -nocase "*something*" $arg]} {
do this
}
Hope that helps.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
daigo
Voice
Posts: 37 Joined: Fri Jun 27, 2014 8:02 pm
Post
by daigo » Sat Jul 26, 2014 2:45 pm
My script is this:
Code: Select all
bind pubm - * test
proc test {nick host hand chan txt} {
set txt [string tolower $txt]
if {[string match -nocase "test" $txt] || [string match -nocase "test?" $txt] || [string match -nocase "test??" $txt] && $nick eq "daigo"} {
set testing [join [lrange [split $txt] 0 end]]
puthelp "PRIVMSG $chan :$testing"
}
return 0
}
Where I put the ? wild cards, I only want them to be numbers
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Sat Jul 26, 2014 3:17 pm
There is no # wild card for [string match], you will have to do it another way.
Fairly sure you should use a regexp or 2 here, but this one is easy enough to fix as string match...
Code: Select all
|| [string match -nocase "test?" $txt] || [string match -nocase "test??" $txt] &&
would be...
Code: Select all
|| [string match -nocase {test[0-9]} $txt] || [string match -nocase {test[0-9][0-9]} $txt] &&