I want to parse CommandLine
which can be in two formats:
command 123
- command with1
parameter (123
)command 123,456
- command with2
parameters (123
and456
)
Here command
- command's name, followed by space ' '
and parameter(s): 123
or 123,456
which separated by comma ,
I've tried to achieve the goal with the code below:
for (int i = 0; i <= CommandLine.TextLength; i++)
{
String[] CommandLineText = CommandLine.Text.Split(' ');
String Commands = CommandLine.Text.ToLower().Trim();
String Command = CommandLineText[0];
String Values = CommandLineText[1];
String[] Parameters = Values.Split(',');
int X = Int32.Parse(Parameters[0]);
int Y = Int32.Parse(Parameters[1]);
}
The problem I'm having is that when the command is in the first format with only 1
number the second parameter becomes out of bounds.