| View previous topic :: View next topic |
| Author |
Message |
pinkel Voice
Joined: 21 May 2008 Posts: 8
|
Posted: Wed May 21, 2008 3:03 pm Post subject: return 0 by number |
|
|
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 |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed May 21, 2008 3:27 pm Post subject: |
|
|
| Code: | | return [expr {![string match {*[0-9.]*} $text]}] |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Papillon Owner

Joined: 15 Feb 2002 Posts: 724 Location: *.no
|
Posted: Wed May 21, 2008 4:08 pm Post subject: |
|
|
or do:
| Code: | | 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 |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed May 21, 2008 6:01 pm Post subject: |
|
|
| Papillon wrote: | or do:
| Code: | | if {[regexp {[1-9]|\.} $text]} { return 0 } |
|
You forgot the 0, it can also be done like this using regexp:
| Code: | | regexp {[0-9.]} $text |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|