J Juan Jan 30, 2005 #1 If I have a string with a valid math expression like " (2 + 28)/1", how can I evaluate it? Thanks, Juan.
If I have a string with a valid math expression like " (2 + 28)/1", how can I evaluate it? Thanks, Juan.
G Guest Jan 30, 2005 #2 You can always work hard and write it yourself, but I think you are not the first to meet this. I found something in CodeProject: http://www.codeproject.com/vb/net/math_expression_evaluator.asp I you search yourself, I'm sure you'll find more.
You can always work hard and write it yourself, but I think you are not the first to meet this. I found something in CodeProject: http://www.codeproject.com/vb/net/math_expression_evaluator.asp I you search yourself, I'm sure you'll find more.
J James Curran Jan 31, 2005 #3 Try the .Math library: http://hebertsoft.com/dotmath/ (Note, he's moving the downloads from http://workspaces.gotdotnet.com/math to https://sourceforge.net/projects/dotmath/, but is still in the process)
Try the .Math library: http://hebertsoft.com/dotmath/ (Note, he's moving the downloads from http://workspaces.gotdotnet.com/math to https://sourceforge.net/projects/dotmath/, but is still in the process)
J Jako Menkveld Jan 31, 2005 #4 I'm not sure how safe this is, but I used this in a non-production environment and it works quite well:
I'm not sure how safe this is, but I used this in a non-production environment and it works quite well:
J Jako Menkveld Jan 31, 2005 #5 Sorry about that, here's the code: ------------------------------------------------------------------------------ using System; using Microsoft.JScript; using Microsoft.JScript.Vsa; namespace VPDBUtils { public class JScriptEvaluator { private static VsaEngine vsaEngine; public static void Initialize() { vsaEngine = VsaEngine.CreateEngine(); } public static void Close() { if (vsaEngine != null) { vsaEngine.Close(); } } private static object EvaluateString(string sStringToEvaluate) { return Eval.JScriptEvaluate(sStringToEvaluate, vsaEngine); } internal static double EvaluateStringAsDouble(string sStringToEvaluate) { return System.Convert.ToDouble(EvaluateString(sStringToEvaluate)); } } }
Sorry about that, here's the code: ------------------------------------------------------------------------------ using System; using Microsoft.JScript; using Microsoft.JScript.Vsa; namespace VPDBUtils { public class JScriptEvaluator { private static VsaEngine vsaEngine; public static void Initialize() { vsaEngine = VsaEngine.CreateEngine(); } public static void Close() { if (vsaEngine != null) { vsaEngine.Close(); } } private static object EvaluateString(string sStringToEvaluate) { return Eval.JScriptEvaluate(sStringToEvaluate, vsaEngine); } internal static double EvaluateStringAsDouble(string sStringToEvaluate) { return System.Convert.ToDouble(EvaluateString(sStringToEvaluate)); } } }