Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Evaluate if a string is a valid mathematical expression?

I would like to test if a string is a valid mathematical expression. I know that with 'load' i can evaluate a string, but if the string is an invalid expression it generates an error message. E.g.

Ans=false
Load("Ans="..Str)()

Str="1+2==3" Gives Ans=True
Str="1+2==4" Gives Ans=False
Str="=1" Gives error message
Str="+=" Gives error message

I would like that cases that generate an error also return 'false'. Is there a clever way to do this? perhaps by trapping the error message from load?

Tagged:

Comments

Sign In or Register to comment.