Advertisement
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.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Query_Mess
- {
- class Program
- {
- static void Main(string[] args)
- {
- var consoleInput = Console.ReadLine();
- string keypattern = @"([^&=?\s]*(?=\=))";
- string valuepattern = @"(?<=\=)([^&=\s]*)";
- var results = new Dictionary<string, List<string>>();
- while (consoleInput != "END")
- {
- var input = consoleInput.Split(new char[] { '&' }).ToList();
- for (int i = 0; i < input.Count; i++)
- {
- Match keymatch = Regex.Match(input[i], keypattern);
- var key = keymatch.Groups[1].Value;
- if (keymatch.Groups[1].Value != null)
- {
- key = Regex.Replace(key, @"\+|%20", x => " ").ToString().Trim(); // skip key+, key+=>key
- }
- if (results.ContainsKey(key) == false)
- {
- results.Add(key, new List<string>());
- }
- MatchCollection matches = Regex.Matches(input[i], valuepattern);
- foreach (Match item in matches)
- {
- string currentMatch = item.Groups[1].Value;
- var splited = currentMatch.Split(new string[] { "%20", "+", "?" }, StringSplitOptions.RemoveEmptyEntries).ToList();
- results[key].Add(String.Join(" ", splited));
- }
- }
- foreach (var item in results)
- {
- Console.Write($"{item.Key}=[{String.Join(", ", item.Value)}]");
- }
- Console.WriteLine();
- results.Clear();
- consoleInput = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement