Re: String to sum
Re: String to sum
- Subject: Re: String to sum
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 12 Oct 2004 09:47:36 -0700
On 10/12/04 9:22 AM, "Mr Tea" <email@hidden> wrote:
>
> Is there a significant overhead or delay associated with 'run script...'?
Yes. As for any osax call, or rather more than some. If you use it in a
repeat loop, a script will be appreciably slower. If you can find a way to
avoid it, do so. For example, if your operations will always be addition of
two operands, you could
set theString to "4 + 5"
set theResult to my AddOperands(theString)
to AddOperands(aString)
set AppleScript's text item delimiters to {" + "}
set {operand1, operand2} to text items of aString
set AppleScript's text item delimiters to {""}
--shouldn't even need a handler to trim leading and trailing white space
set set {operand1, operand2} to {operand1 as number, operand2 as number}
set theResult to operand1 + operand2
return theResult
end AddOperands
You can also have routines for subtraction, multiplication, division,
exponents, and whatever other string mathematical operators you know might
occur in the string. You'll need tests for strings with no such operators
(and more than one, if possible).
These will be a lot faster than run string.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden