Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

eval function?

2 views
Skip to first unread message

RP

unread,
Apr 24, 2003, 4:53:38 PM4/24/03
to
Hi all,

I wanted to know if there was any equivalent of the eval function that
javascript has. basically if i can construct a statement in a string and
then evaluate it.

thanks!


Wiktor Zychla

unread,
Apr 25, 2003, 7:27:57 AM4/25/03
to
> I wanted to know if there was any equivalent of the eval function that
> javascript has. basically if i can construct a statement in a string and
> then evaluate it.

http://www.codeproject.com/csharp/runtime_eval.asp


Joubert

unread,
May 1, 2003, 1:47:16 PM5/1/03
to
Also try http://www.lundin.info

They have a math expression parser in the info.lundin.Math namespace.

J


"RP" <r...@nospam.com> wrote in message
news:u6fEHJqC...@TK2MSFTNGP10.phx.gbl...

MikeB

unread,
May 1, 2003, 2:50:21 PM5/1/03
to

"RP" <r...@nospam.com> wrote in message
news:u6fEHJqC...@TK2MSFTNGP10.phx.gbl...
> I wanted to know if there was any equivalent of the eval function that
> javascript has. basically if i can construct a statement in a string and
> then evaluate it.

Since the .NET framework has a JScript.NET compiler, you can do the
following...

1) copy the following to a .js file (for example myeval.js):

// =============================
package JSUtil {
class Util {
static public function Eval( s : String) {
return( eval( s));
}
}
}

// =============================

2) compile it at the command line using "jsc /t:library myeval.js"

3) in your VB.NET or C# (or whatever .NET language), reference the following
assemblies:

myeval.dll - (the library built above)
Microsoft.JScript - (the JScript.NET runtime)

4) call JSUtil.Util.Eval() when you want to evaluate a string. For example:

Console.WriteLine( "2+6")

will print "8" on the console.

--
MikeB


0 new messages