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.

Numeric wild card

Help for those learning Tcl or writing their own scripts.
Post Reply
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Numeric wild card

Post by daigo »

I want a wild card to be restricted to numbers only. How do I make the * and/or ? wildcards to be only numerical?
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

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.
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Post by daigo »

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
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

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] &&
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply