Re: Check if it is a number
Re: Check if it is a number
- Subject: Re: Check if it is a number
- From: christian vick <email@hidden>
- Date: Thu, 28 Nov 2002 10:49:25 +0100
>
Hi all, I have a string like this one "12A4B5" and I want to check for
>
each text item if this is a number and do something or if this not a
>
number and do another thing.
>
Is there a better way than using a try block to check if the current
>
text item is a number ?
>
Currently I'm using this method :
>
>
set my_text to "12A4B5"
>
repeat with from 1 to count of my_text
>
set current_item to item i of my_text
>
try
>
current_item as number
>
--this is a number
>
on error
>
--this is not a number
>
end
'as number' is not reliable, since AS doesn't error on some charcters, i.e.
space, plus, minus. Not enough, this vary in different AS versions. Better
use...
if myChar is in {"1","2","3", ......} then
-- is number
end
Greetings
Christian Vick
_______________________________________________
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.