Click here to Skip to main content
15,899,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a tool which contains a textbox and Save button.
In the textbox user will enter mathematical expression like "2*(UpperBound - LowerBound)" and then clicks the save button to save the expression in xml.
But before saving the expression into xml want to validate it.
For this i tried to create a method like ValidateExpression(string expresion,List<string> unknownvariables) here the list contains the strings "UpperBound ","LowerBound" ant etc.

Is there any method like this to validate the expression containing unknown variables.
Posted

1 solution

Of course there is a method: parsing the mathematical expressions. You may find a lot of examples, just Googling[^].
Optionally, after parsing, you may validate all the found identifiers using the list of 'unknowns'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900