If I have a string with a valid math expression such as:
String s = \"1 + 2 * 7\";
Is there a built in library/function in .NET that will p
Actually there is kind of a built in one - you can use the XPath namespace! Although it requires that you reformat the string to confirm with XPath notation. I've used a method like this to handle simple expressions:
public static double Evaluate(string expression)
{
var xsltExpression =
string.Format("number({0})",
new Regex(@"([\+\-\*])").Replace(expression, " ${1} ")
.Replace("/", " div ")
.Replace("%", " mod "));
return (double)new XPathDocument
(new StringReader(" "))
.CreateNavigator()
.Evaluate(xsltExpression);
}