Saturday, 31 August 2013

Construct VB code based on a string containing the statements

Construct VB code based on a string containing the statements

What I'm trying to do this is writing a simple parser for the following
case in .NET that given a string like this :
If ([1] >=60 : 50; If ([1]>=50 : 40; If ([1]>=40 : 30; If([1]>=30 :
20;0))))
should return one like this :
If ([1] >=60) Then
Return 50
ElseIf ([1]>=50) Then
Return 40
ElseIf ([1]>=40 ) Then
Return 30
ElseIf([1]>=30 ) Then
Return 20
Else
Return 0
End If
Using split to divide the string into multiples strings first by ";" and
then by ":" and with the use of For Each, I have managed to do it(though
not in a very elegant way) That's why I wonder if there wouldn't be a more
elaborate way of doing this, using Regex perhaps
One last thing, do you think there is a quick way to get all the numbers
enclosed in square brackets(variable IDs) without duplicates .
For instance , given a string like :
If ([3] = 'M' AND [4] = 'S' AND [5]>=1000 : 20/100 * [5]; 500)
I get, let's say , an array of integers containing (3,4,5)
What's the best way to implement such things in .NET?? Any help would be
greatly appreciated
P.S. I couldn't find a good title for the question.

No comments:

Post a Comment