| View previous topic :: View next topic |
| Author |
Message |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sat Jul 26, 2014 1:56 pm Post subject: Numeric wild card |
|
|
| I want a wild card to be restricted to numbers only. How do I make the * and/or ? wildcards to be only numerical? |
|
| Back to top |
|
 |
Get_A_Fix Master

Joined: 07 May 2005 Posts: 206 Location: New Zealand
|
Posted: Sat Jul 26, 2014 2:10 pm Post subject: |
|
|
Something like
| Code: |
proc isnum {string} {
if {[regexp {^-?\d+(\.\d+)?$} $string]} {
return 1;
}
return 0;
}
|
then you are able to make if statements, like..
| Code: |
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: |
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. |
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sat Jul 26, 2014 2:45 pm Post subject: |
|
|
My script is this:
| Code: | 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 |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Jul 26, 2014 3:17 pm Post subject: |
|
|
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: | | || [string match -nocase "test?" $txt] || [string match -nocase "test??" $txt] && | would be... | Code: | | || [string match -nocase {test[0-9]} $txt] || [string match -nocase {test[0-9][0-9]} $txt] && |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
|