RE: Numbers in a variable
RE: Numbers in a variable
- Subject: RE: Numbers in a variable
- From: "Ruby Madraswala" <email@hidden>
- Date: Fri, 1 Aug 2003 08:45:28 -0400
- Thread-topic: Sorting a List Solution Revisited was Sorting A List - Need Help
Steven. David and Kai
Thanks for the help. I tried most of suggestions, worked, some with few changes. The one I ended up using was the this one line
If (character 1 of aword) is in "0123456789" then
("first character" gave me an error message).
Thanks again
Ruby
-----Original Message-----
From: Steven D. Majewski [
mailto:email@hidden]
Sent: Thursday, July 31, 2003 3:16 PM
To: Ruby Madraswala
Cc: email@hidden
Subject: Re: numbers in a variable.
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.