Possible Duplicates:
Open Source Expression Engines (Java)
Convert mathematical string to int
Hello,
If I have a string that says anything along the lines of "x+6", how can I turn that into a function that can be evaluated with me substituting a variable in for x.
For example, say I want to run it into a foreach loop:
String func = "x+6";
for(int i : ints)
y = func(i);
before you say "just make it a method," know that the string can change according to the program. that is to say, at any point the string could be "x^2-2", "x/2*3", "4^x", etc...
I want a way to turn a string into a function that i can evaluate. thanks!