I'm trying to interpret string commands to run associated scripts. This is what I have so far:
// A typical command that can come from a TextBox control
string command = "Create";
// Remove all white space
command = System.Text.RegularExpressions.Regex.Replace(command, @"\s", "");
// Make case insesitive by converting to lowercase
command = command.ToLower();
switch (command)
{
case "create": /* Run create script*/ break;
case "delete": /* Run delete script*/ break;
// etc.
}
This works fine until I introduce parameters associated with a particular command.
I thought that this could be denoted by round brackets so a more complex command would look like:
string command = "Create(paramA, paramB, etc.)"
Assuming I'm on the correct path with this approach, what would be a good method for detecting and interpreting the parameters?
Rules for the command are:
'(' ')' opens and closes the set of parameters ',' separates each parameter
In other words how can I detect the beginning and end of the parameters and correctly separate each one?
The other problem of course is to separate the command itself from the parameters.
I thought about using:
command.StartsWith("create"); // etc.
but this will not work within a switch case conditional structure.