0

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?

Eran
  • 387,369
  • 54
  • 702
  • 768

2 Answers2

1

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.

Eran
  • 387,369
  • 54
  • 702
  • 768
0

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.

Community
  • 1
  • 1
TuanDT
  • 1,627
  • 12
  • 26