Possible Duplicates:
Is there a string math evaluator in .NET?
Converting string expression to Integer Value using C#
Best and shortest way to evaluate mathematical expressions
c# evaluating string “3*(4+2)” yield int 18
Is there a way to calculate math expressions like (2-3/4*12) in a different way than presented here?
DataTable has a Compute method that allows you to write this:
var result = new DataTable().Compute("2-3/4*12", null);
Note that this is limited to simple math expressions.
Other option consist in using a dynamic language in the DLR such as IronPython and IronRuby. Check-out this post:
var engine = new IronPython.Hosting.PythonEngine();
double result = pythonEngine.EvaluateAs<double>("2-3/4*12");
You may also check the NCalc library on GitHub.