I've got a string containing a mathematical expression. How can I calculate the value of the expression in the string? Example: stringExp = "4*8"; How can I get the value of 32? I can't figure out how to parse the operator properly.
depends on how complicate your expressions are (e.g. order of operators: 1 + 2 * 3).
you could work with the indexOf() method of String, or the StringTokenizer class or the regular expressions for simple stuff (e.g. just the 4 basic operators without precedence rules).