Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- class DictionaryFirst
- {
- static void TextSearch(string wordToFind, Dictionary<string, string> before)
- {
- foreach (KeyValuePair<string, string> kvp in before)
- {
- if ((wordToFind == kvp.Key) == true)
- {
- string answer = string.Format("{0} - {1}", kvp.Key, kvp.Value);
- Console.WriteLine(answer);
- Environment.Exit(0);
- }
- }
- Console.WriteLine("The word can not be found.");
- }
- static void Main()
- {
- string dictionary = ".NET - platform for applications from Microsoft\n" +
- "CLR - managed execution environment for .NET\n" +
- "namespace - hierarchical organization of classes";
- Dictionary<string, string> before = new Dictionary<string, string>();
- string pattern = @"(?<before>.+) - (?<after>.+)";
- string input = dictionary;
- MatchCollection matches = Regex.Matches(input, pattern);
- for (int i = 0; i < matches.Count; i++)
- {
- before.Add((matches[i].Groups["before"].ToString().Trim(' ')), matches[i].Groups["after"].ToString().Trim(' '));
- }
- string wordToFind = "namespace";
- TextSearch(wordToFind, before);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement