Convert String Literal into Operation
After searching on several forums for a while IW as unable to find similar posts, so I was hoping I would be able to get some help. I want to convert a string literal into an operation, however I'm not sure how to start. Here's a (bad) attempt I've made so far
Code :
class test
{
public static void main (String args[])
{
String eq1 = "x/2+6";
double eq2 = eq1; // <- want "double eq2 = x/2+6;"
System.out.println (eq2);
}
}
Re: Convert String Literal into Operation
Search the net for the Java scripting API. Also take a look at the classes and interfaces in the javax.script package.
I've never used this stuff, so I can't advise further.
db
Re: Convert String Literal into Operation
Perhaps a better example would be;
Code :
double eq2 = evaluateToDouble(eq1);
Now you need to find the class with a method like that.
Re: Convert String Literal into Operation
Use python, or some other similar scripting language. The alternative is to write a parser yourself (not simple!). With Jython, you can integrate your Java program with Python.
Re: Convert String Literal into Operation
With a bit of Google and help at another forum, I found JEval, which worked great