private StringCollection SplitCmdLineArguments(string argumentString){
StringCollection args = new StringCollection();
if (argumentString == null || argumentString.Length == 0)
return args;
// This regular expression is: blank*(nonblanks|stringLiteral)+
string strReArgs = "\\s*([^\\s\\\"]|(\\\"[^\\\"\\n]*\\\"))+";
Regex re = new Regex(strReArgs);
MatchCollection matches = re.Matches(argumentString);
if (matches != null && matches.Count != 0){
foreach (Match match in matches){
string arg = match.ToString().Trim();
int quotes = 0;
while ((quotes = arg.IndexOf("\"", quotes)) != -1){
if (quotes == 0)
arg = arg.Substring(1);
else if (arg[quotes-1] == '\\')
quotes += 1;
else
arg = arg.Remove(quotes, 1);
}
args.Add(arg);
}
}
return args;
}