I have seen a couple of other creative solutions as well,
but this solution i came up with, because it did the work, it was kind of
efficient, and i needed to write no code.
public static double Evaluate ( string expression )
{
// That is some code instruction, is'nt it? :)
return (double) new System.Xml.XPath.XPathDocument
( new StringReader("<r/>")).CreateNavigator().Evaluate
( string.Format("number({0})", new
System.Text.RegularExpressions.Regex(@"([\+\-\*])")
.Replace(expression, " ${1} ")
.Replace("/", " div ")
.Replace("%", " mod ") ) );
}
HTH.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jeff Lindholm" <je**@lindholm.org> wrote in message
news:CJ******************@newssvr19.news.prodigy.c om...
( ( 3 + 5 ) / 2 ) > 4 --> this should return 0 or false( ( 3 + 6 ) /
3 ) >
( ( 5 + 3 ) / 4 ) --> this should return 1 or trueThanks for any comment
or
advice.
There was an old post fro Scott Alen but I couldn't follow what he
refered
to to make it happens. Currently I have to parse and evaluate the
expression myself and it's messy and very slow. Thanks for any comment
and
advise.
Here is the test I did with information from here
----- Math.js -----------
class JsMath
{
static function Eval(MathExpression : String) : double
{
return eval(MathExpression);
};
}
------ Test.cs ----------
using System;
using System.Text;
class Test
{
static void Main(string[] args)
{
System.Console.WriteLine(JsMath.Eval("(1 + 2) * 8"));
}
}
----------------------
jsc /t:library Math.js
csc -r:Microsoft.JScript.dll -r:Math.dll test.cs
change test.cs as needed for what you want.