Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace QueryMess
- {
- class Program
- {
- static void Main()
- {
- var stringList = new List<string>();
- Regex pattern = new Regex(@"(\w+\+?%?)=([^&]+)");
- string input = Console.ReadLine();
- Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();
- while(input != "END")
- {
- input = input.Replace("?", "&");
- stringList.Add(input);
- input = Console.ReadLine();
- }
- for (int i = 0; i < stringList.Count; i++)
- {
- MatchCollection matches = pattern.Matches(stringList[i]);
- foreach(Match match in matches)
- {
- string name = Regex.Replace(match.Groups[1].ToString(), @"\+?%20\+?|\+", " ").Trim();
- string value = Regex.Replace(match.Groups[2].ToString(), @"\+?%20\+?|\+", " ").Trim();
- if(!result.ContainsKey(name))
- {
- result[name] = new List<string>();
- }
- result[name].Add(value);
- //Console.WriteLine(name);
- //Console.WriteLine(value);
- }
- foreach(var pair in result)
- {
- Console.Write("{0}=[{1}]", pair.Key, string.Join(", ", pair.Value));
- }
- Console.WriteLine();
- result.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment