Ok, so I'm spitting command line arguments by spaces, like Command Prompt, but the problem is, if the user tries to type in DoStuff "argument that has spaces but is quoted" it will not split it correctly. I am using a console application. I've tried to do it like this: baseCommand is the string that the user types in unparsed, and secondCommand is supposed to be the second argument.
int firstQuoteIndex = baseCommand.IndexOf('"');
if (firstQuoteIndex != -1)
{
int secondQuoteIndex = baseCommand.LastIndexOf('"');
secondCommand = baseCommand.Substring(firstQuoteIndex,
secondQuoteIndex - firstQuoteIndex + 1).Replace("\"", "");
}
This works well, but first, it's messy, and second, I'm not sure how to do this if the user types in something like this:
DoSomething "second arg that has spaces" "third arg that has spaces"
Keep in mind that the user doesn't have to type in quotes if the arg(s) don't have quotes. Does anybody have any suggestions, Thanks.