String as equation?

Discussion in 'iPhone/iPad Programming' started by wesg, Sep 28, 2010.

  1. macrumors regular

    wesg

    Joined:
    Jan 2, 2008
    Location:
    Toronto, ON
    #1
    Has anyone had success turning strings into equations?

    ie. take a stored string of 2*5+6 and output 16
     
  2. macrumors 6502a

    (marc)

    Joined:
    Sep 15, 2010
    Location:
    the woods
    #2
    You'll have to write a parser.

    EDIT: This might not be trivial. I googled "c equation parser" and found this.
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7)

    Perhaps you can use JavaScript's eval() function.
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
  5. thread starter macrumors regular

    wesg

    Joined:
    Jan 2, 2008
    Location:
    Toronto, ON
    #5
    Thanks for all the suggestions. I'm going to look into storing them as actual values... we'll see how it goes.
     

Share This Page