IRCのようなコマンド形式を作成しようとしています。
/commandname parameter1 "parameter 2" "parameter \"3\"" parameter"4 parameter\"5
これは(理想的には)パラメータのリストを私に与えるでしょう:
parameter1
parameter 2
parameter "3"
parameter"4
parameter\"5
今私が読んだことから、これはまったく些細なことではなく、他の方法で行うのもよいでしょう。
考え?
以下は私が必要とする仕事をするC#コードです:
public List<string> ParseIrcCommand(string command)
    {
        command = command.Trim();
        command = command.TrimStart(new char[] { '/' });
        command += ' ';
        List<string> Tokens = new List<string>();
        int tokenStart = 0;
        bool inQuotes = false;
        bool inToken = true;
        string currentToken = "";
        for (int i = tokenStart; i < command.Length; i++)
        {
            char currentChar = command[i];
            char nextChar = (i + 1 >= command.Length ? ' ' : command[i + 1]);
            if (!inQuotes && inToken && currentChar == ' ')
            {
                Tokens.Add(currentToken);
                currentToken = "";
                inToken = false;
                continue;
            }
            if (inQuotes && inToken && currentChar == '"')
            {
                Tokens.Add(currentToken);
                currentToken = "";
                inQuotes = false;
                inToken = false;
                if (nextChar == ' ') i++;
                continue;
            }
            if (inQuotes && inToken && currentChar == '\\' && nextChar == '"')
            {
                i++;
                currentToken += nextChar;
                continue;
            }
            if (!inToken && currentChar != ' ')
            {
                inToken = true;
                tokenStart = i;
                if (currentChar == '"')
                {
                    tokenStart++;
                    inQuotes = true;
                    continue;
                }
            }
            currentToken += currentChar;
        }
        return Tokens;
    }