Re: Check if it is a number
Re: Check if it is a number
- Subject: Re: Check if it is a number
- From: Paul Skinner <email@hidden>
- Date: Thu, 5 Dec 2002 17:42:06 -0500
On Thursday, December 5, 2002, at 10:35 AM, has wrote:
[Haven't been following this thread, so apologies for belly-flopping
into the pool and upsetting the civil swimmers...]
kersplooosh! I hope you tied your drawstring.
snip...
I thought that the code I posted on Sat Nov 30, 2002 was nice because
you could read it and easily understand it's logic. Below, I've
slightly modified it by adopting NG's '(count of n)=0' vs. ' n is "" '
and single 'not' construction. The test for n contains a space was
removed as redundant...
on NumeralsOnly(n)
try
n as number
return not ((count of n) = 0 or n contains "-" or n contains "+")
on error
return false
end try
end NumeralsOnly
I can't imagine that speed is a great consideration to the OP since it
was to verify user input. But AppleScripters being gluttons for
punishment that they are, this is as fast as I can get it.
.038 seconds per 1000 iterations with an invalid null argument. ie user
inputs nothing
.088 seconds per 1000 iterations with an invalid negative signed number.
.129 seconds per 1000 iterations with an invalid positive signed number.
.13 seconds per 1000 iterations with a valid number.
.8 seconds per 1000 iterations with an invalid non number. ie user
inputs "hello". Failed coercion is sloooow. : (
P.S. I couldn't get your testing code to work, it always executed the
first if-then statement even when it evaluated to false. Weird. Still
trying to figure it out.
--
Paul Skinner
Mac OS X 10.2.2
AppleScript 1.9
OSAXen installed
ColorSyncScripting.app
Digital Hub Scripting.osax
FontSyncScripting.app
Image Capture Scripting.app
Keychain Scripting.app
StandardAdditions.osax
URL Access Scripting.app
Adobe Unit Types
24U Hex OSAX
GetMilliSec.osax
KinderShell.osax
XML Tools.osax
_______________________________________________
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.