1 Reply Latest reply on Mar 22, 2007 2:25 AM by doug777

    Evaluating String Expressions.....

      Ok, so I have a question, and after searching for over an hour, I came here, hoping someone can help me.

      I have either a string of text, or an array (I can do both, which ever is easier).
      My string would be something like "19 * .01", or my array would be {19,*,.01}.

      What I need to be able to do is to evaluate it to be 19 * .01, which would give me a number of .19 . I know how to do this in ColdFusion, but I just can't seem to get it to work in A3.

      I've tried using parseFloat, passing in the string, which gave me 19 - like it quit at the " * ". Everything else has just thrown erros.

      Any ideas???

        • 1. Re: Evaluating String Expressions.....
          doug777 Level 1
          I don't think there's any way to make the compiler recognize a character from a string as an ActionScript operator.

          I would keep the two numeric parts as variables num1 and num2, and if the operator can vary, set a variable like op = 1 if you need an addition, op = 2 if you need a multiplication and then use a switch statement to send the two variables to the appropriate line where you already have the operator e.g if op == 1 then num1+num2, if op == 2 then num1*num2 etc.