Possible Duplicate:
calculate result from a string expression dynamically
I have the following formula saved in XML as element value- “d1*2”.
After I extract this from the XML as a string how can I assign a value to the “d1”
and calculate the formula result?
This looks like it’s exactly what you’re looking for:
https://github.com/Giorgi/Math-Expression-Evaluator
The author’s done a really good and thorough write-up of the usage and design here:
http://www.aboutmycode.com/net-framework/building-expression-evaluator-with-expression-trees-in-csharp-table-of-contents/
Usage goes like this (copied from the examples):
Google is, of course, your friend… there are a bunch of others out there, but this by far looks like the most mature project.
EDIT: This other SO answer also mentions NCalc, which is similar: https://stackoverflow.com/a/10063089/381587