I have a String (let's say) comp = "3 == 5";
How can I convert that String
into a boolean
expression that can be evaluated to true
or false
?
I have a String (let's say) comp = "3 == 5";
How can I convert that String
into a boolean
expression that can be evaluated to true
or false
?
There's no easy way to do it. That's what compilers do. You have to parse the String, identify the type of each token (in your example, two int constants and one equality operator) and evaluate the expression.
Evaluating a math expression given in string form
That post concerns mathematical expression, but after testing it, I realized it also applies to boolean expression as well.