For simple expressions you can use XPath:

 XPathNavigator nav = new XmlDocument ().CreateNavigator ();
 Console.WriteLine (nav.Evaluate ("(7-1) div 2").ToString ());

Beyond that, you'll either need to write your own expression evaluator, or
build/load dynamic assemblies.

Here's a couple of articles:
http://codeproject.com/vb/net/math_expression_evaluator.asp
http://codeproject.com/dotnet/evaluator.asp

Piers. 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Gonia 
> Eric - egonia
> Sent: Wednesday, January 21, 2004 9:41 AM
> To: '[EMAIL PROTECTED]'
> Subject: [Mono-list] eval statement
> 
> Does anyone have a recommendation on how I can create an eval 
> method similar to perl's or php's.
> 
> I would like to take a string like "(7-1)/2" and pass it to a 
> method that would return the value of the mathematical operation.
> 
> Thanks for any help you can provide,
> Eric
> 

_______________________________________________
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to