Question Evaluating a string expression at runtime

TrevorC

New member
Joined
Aug 17, 2009
Messages
4
Programming Experience
10+
I have a application that allows the user to enter a series of nested filtering commands.
E.g "Name starts with x or ((Description contains y or Property1 is On) and Property2 > 100)"

I can preprocess this and distill it down to a string in the form of an expression of True and False's
ie, To "True or ((False or True) and False)"

Is there a simple way to have this final expression evaluated without having to write a complex evaluator myself?

Or does anyone know of some example code that will do this?

I have seen a method of evaluating this by compiling a dummy function at runtime but as I need to process this against possibly thousands of records that solution is too slow.

BTW These are not all fields in a database so I cannot use Queries or SQL etc.

Thanks in advance
Trev
 
Or does anyone know of some example code that will do this?

:)

VB.NET:
        Dim InputForEvaluation As String = ""
        Dim Result As String = ""
        InputForEvaluation = "True or ((False or True) and False)"
        InputForEvaluation = "7 + (3 * 6)"
        Dim dtTemp As New System.Data.DataTable
        Result = dtTemp.Compute(InputForEvaluation, "").ToString
        dtTemp.Dispose()
        MessageBox.Show(Result)
 
Back
Top