Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class Program
- {
- public static void Main()
- {
- const string pattern = @"([^&?]+?)=([^&?]+)";
- Regex whitespacePattern = new Regex(@"(%20|\+)+");
- string input = Console.ReadLine();
- while (input != "END")
- {
- var queries = new Dictionary<string, List<string>>();
- var matches = Regex.Matches(input, pattern);
- foreach (Match match in matches)
- {
- string key = match.Groups[1].ToString();
- key = whitespacePattern.Replace(key, " ").Trim();
- string value = match.Groups[2].ToString();
- value = whitespacePattern.Replace(value, " ").Trim();
- if (!queries.ContainsKey(key))
- {
- queries.Add(key, new List<string>());
- }
- queries[key].Add(value);
- }
- foreach (var query in queries)
- {
- Console.Write(
- "{0}=[{1}]",
- query.Key,
- string.Join(", ", query.Value));
- }
- Console.WriteLine();
- input = Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement