Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Converting a string to a command?

    Hi,

    I was wondering if it was possible to convert a string like "2x * x + 3x +5" to operators and integers so that this could actually be calculated? I'm sure there is a way but I really don't know how I would go about doing that. I have designed an algorithem before that was able to get easy functions simply by reading each character and then deciding on what to do, but that was very limited, and would be way to complex.

    Anybody have a tip of how this can be achieved?

    Cheers,
    Chris

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You would need to parse it and then run the correct commands based on whats in the string. It wouldn't be too hard, if you want to support more complex equations that use parenthesis and brackets it would be harder but not by much. You also have to remember the order of operations in math, you can't simply execute from left to right.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •