egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Numeric wild card

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
daigo
Voice


Joined: 27 Jun 2014
Posts: 37

PostPosted: Sat Jul 26, 2014 1:56 pm    Post subject: Numeric wild card Reply with quote

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
View user's profile Send private message
Get_A_Fix
Master


Joined: 07 May 2005
Posts: 206
Location: New Zealand

PostPosted: Sat Jul 26, 2014 2:10 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
daigo
Voice


Joined: 27 Jun 2014
Posts: 37

PostPosted: Sat Jul 26, 2014 2:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Jul 26, 2014 3:17 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber