• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
IS: Re: String to sum -- WAS: Bug in String Coercions containing Operators?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >IS: Bug in String Coercions containing Operators? -- WAS: Re: String to sum (From: Johnny AppleScript <email@hidden>)

  • Prev by Date: Re: IS: Bug in String Coercions containing Operators? -- WAS: Re: String to sum
  • Next by Date: Re: String to sum
  • Previous by thread: Re: IS: Bug in String Coercions containing Operators? -- WAS: Re: String to sum
  • Next by thread: Re: String to sum
  • Index(es):
    • Date
    • Thread