Re: numbers in a variable.
Re: numbers in a variable.
- Subject: Re: numbers in a variable.
- From: "Steven D. Majewski" <email@hidden>
- Date: Thu, 31 Jul 2003 15:16:28 -0400
On Thursday, July 31, 2003, at 01:58 PM, Ruby Madraswala wrote:
How do I check if a variable contains numbers (can range from 1 to
99)? I tried:
If newword contains [1-99] then
Do something
Else
It's a heading
End if
I don't get any error message and "do something" does not work which
right now is just few display statements.
No -- you don't get any error message. Why would you.
Try evaluating [1-99] in script editor and you'll see that it
evaluates to {-98}.
so:
If newword contains {-98} then
...
is likely to be mostly false.
AS doesn't have regexes. Looks like you're trying to write in Perl
rather than AppleScript!
There are some OSAX that support regex, I believe.
If you're on OSX, you can call out to PERL or grep or awk or whatever
with 'do shell script'
'contains' is a one to many comparison, so if you're comparing two
sequences (strings),
you'll have to iterate thru one of them. Although, from your example
data, maybe you just
want to check if the first character is a digit ? :
if (first character of "4 test" ) is in "0123456789" then ...
Otherwise, you can do something like :
on has_digit(myword)
repeat with d from 0 to 9 -- AS will coerce the numbers to string for
comparison, or else use: repeat with d in "0123456789"
if myword contains d then return true
end repeat
return false
end has_digit
if has_digit( newword ) then ...
-- Steve Majewski
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.