IS: Re: String to sum -- WAS: Bug in String Coercions containing Operators?
IS: Re: String to sum -- WAS: Bug in String Coercions containing Operators?
- Subject: IS: Re: String to sum -- WAS: Bug in String Coercions containing Operators?
- From: Johnny AppleScript <email@hidden>
- Date: Tue, 12 Oct 2004 11:27:55 -0600
Title: IS: Re: String to sum -- WAS: Bug in String Coercions containing Operators?
This version works because the formulas are predictable; not sure if this concept will inspire the original poster to a faster solution or not-- JA
set theStrings to {"4 + 5", "4 * 5", "4 - 5", "4 / 5"}
set theResults to {}
repeat with i from 1 to number of items in theStrings
set theString to item i of theStrings
try
set operand1 to word 1 of theString
set operand2 to word -1 of theString
if theString contains "+" then set theResult to operand1 + operand2
if theString contains "-" then set theResult to operand1 - operand2
if theString contains "*" then set theResult to operand1 * operand2
if theString contains "/" then set theResult to operand1 / operand2
on error errMSG
set theResult to errMSG
end try
set the end of theResults to theResult
end repeat
return theResults
-- > {9, 20, -1, 0.8}
_______________________________________________
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