I'm looking for an algorithm/library to parse this command line:
var cmd = "foo /option:value /option2:valueof /etc:.. baa /t:4 etc xd";
to:
foo => { "option", "value" },
       { "option2", "valueof" },
       {"etc", ".."},
baa => {"t", "4"},
etc => {"xd", ""},
I tried in 'pure mode'(C-like) just using if and for. But an solution with regular expression or linq is very appreciated.
my code(not working):
var cmd = "foo /option:value /option2:valueof /etc:.. baa /t:4 etc xd";
            var keys = new Dictionary<string, Dictionary<string,string>>();
            for (int pos = 0, len = cmd.Length; pos < len; pos++)
            {
                StringBuilder buffer = new StringBuilder();
                char c = cmd[pos];
                if (c == '/') 
                {
                    StringBuilder optionName = new StringBuilder();
                    StringBuilder optionValue = new StringBuilder();
                    do
                    {
                        c = cmd[pos++];
                        if (c == ':')
                        {
                            do
                            {
                                c = cmd[pos++];
                                optionValue.Append(c);
                            } while (c != '/' || c != ' ');
                        }
                        else
                        {
                            optionName.Append(c);
                        }
                    } while (c != ' ');
                    keys.Add(buffer.ToString(),
                        new Dictionary<string, string>
                        {
                            {optionName.ToString(), optionValue.ToString()}
                        });
                }
            }
it given an Index was outside the bounds of the array.
Thanks in advance.
 
     
     
     
    