Advertisement
Guest User

reshenie

a guest
Oct 19th, 2016
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. class QueryMess
  7. {
  8. static void Main()
  9. {
  10. string pattern = @"([^&=?]*)=([^&=]*)";
  11. string regex = @"((%20|\+)+)";
  12. string inputLine;
  13.  
  14. while (!((inputLine = Console.ReadLine()) == "END"))
  15. {
  16. Regex pairs = new Regex(pattern);
  17. MatchCollection matches = pairs.Matches(inputLine);
  18. Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
  19. for (int i = 0; i < matches.Count; i++)
  20. {
  21. string field = matches[i].Groups[1].Value;
  22. field = Regex.Replace(field, regex, word => " ").Trim();
  23.  
  24. string value = matches[i].Groups[2].Value;
  25. value = Regex.Replace(value, regex, word => " ").Trim();
  26.  
  27. if (!results.ContainsKey(field))
  28. {
  29. List<string> values = new List<string>();
  30. values.Add(value);
  31. results.Add(field, values);
  32. }
  33. else if (results.ContainsKey(field))
  34. {
  35. results[field].Add(value);
  36. }
  37. }
  38. foreach (var pair in results)
  39. {
  40. Console.Write("{0}=[{1}]", pair.Key, string.Join(", ", pair.Value));
  41. }
  42. Console.WriteLine();
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement