evaluate expression string programmatically

  • Thread starter Thread starter Zeng
  • Start date Start date
Z

Zeng

Hello,

I just wonder if there is a way to programmatically evaluate expression
strings such as
( ( 3 + 5 ) / 2 ) > 4 --> this should return 0 or false
( ( 3 + 6 ) / 3 ) > ( ( 5 + 3 ) / 4 ) --> this should return 1 or true

Thanks for any comment or advice.
 
thanks.... but I couldn't follow the articles there to do the evaluation of
the expression in C#, would you or someone else have a pointer where I find
better instructions or examples?

thanks!
 
This is hacky, but works:

XmlDocument doc=new XmlDocument();
XPathNavigator nav=doc.CreateNavigator();
doc.LoadXml("<xml/>");

XPathExpression xpr=nav.Compile(" ( ( 3 + 5 ) div 2 ) > 4 ");

Console.WriteLine("xpr.Expression={0}", nav.Evaluate(xpr));
 
Thats a great little hack...

Xpath Evaluate will also support rounding and other number functions.

ok,
aq
 
Back
Top