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.

return 0 by number

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pinkel
Voice
Posts: 8
Joined: Wed May 21, 2008 2:59 pm

return 0 by number

Post by pinkel »

I am looking for the code that will return 0, if the $text contains one or more of the numbers: 1234567890 and/or a . (dot)

tnx
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

return [expr {![string match {*[0-9.]*} $text]}]
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

or do:

Code: Select all

if {[regexp {[1-9]|\.} $text]} { return 0 }
difference being that in Sir_Fz example you get the return 1 when no match is made. Of course you can just toss the string match into an if statement as I have done and get the desired result. Just wanted to show it done with regexp
Elen sila lúmenn' omentielvo
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Papillon wrote:or do:

Code: Select all

if {[regexp {[1-9]|\.} $text]} { return 0 }
You forgot the 0, it can also be done like this using regexp:

Code: Select all

regexp {[0-9.]} $text
Post Reply