/// <summary> /// Parses the text to <see cref="Flags"/>, <see cref="Pairs"/> and <see cref="RawArguments"/>. /// </summary> /// <param name="text">The message text.</param> protected void Parse(string text) { RawString = text.Remove(0, Command.CommandPrefix.Length); var parts = Regex.Matches(text, @"[\""].+?[\""]|[^ ]+") .Cast <Match>() .Select(m => m.Value) .ToList(); Identifier = parts[0].Remove(0, Command.CommandPrefix.Length); parts.RemoveAt(0); // removes the identifier from the list. ArgumentString = RawString.Remove(0, Identifier.Length + 1); for (int i = 0; i < parts.Count; i++) { string part = parts[i]; if (part.StartsWith(FlagPrefix)) { string flag = part.Remove(0, FlagPrefix.Length); // remove the flag prefix. _flags.Add(flag); } else if (part.StartsWith(PairPrefix)) { string key = part.Remove(0, PairPrefix.Length); // remove the pair prefix. string value = string.Empty; if (parts.Last() != part) { value = parts[i + 1]; // save the next as the value and skip it. } _pairs.Add(key, value); i++; } else // is a raw argument { _rawArgs.Add(part); } } }