public static void FindWords(FindWordCommand opts, HashSet <string> wordsDic)
        {
            opts.WordToGuess = RegexForNumber.Replace(opts.WordToGuess, MatchEvaluator);
            opts.WordToGuess = @"\A" + opts.WordToGuess
                               .Replace("_", @"(\w|-)")
                               .ToLower() + @"\Z";
            var regex   = new Regex(opts.WordToGuess);
            var matches = wordsDic
                          .Where(word => regex.Match(word).Success)
                          .ToHashSet();

            PrintHandler.PrintMatches(matches);
        }
Exemple #2
0
        private static void Main()
        {
            var words = TxtReader.ReadTxt(Path.Combine("Dics", "custom.txt"));

            Console.WriteLine("Введите слово по шаблону: \"__п___а__\"\n");
            var consoleInput = string.Empty;

            while (true)
            {
                consoleInput = Console.ReadLine();
                if (consoleInput == string.Empty)
                {
                    break;
                }

                var args = Commands.Any(command => consoleInput != null && consoleInput.StartsWith(command))
                    ? consoleInput?.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)
                    : new[] { consoleInput };
                Parser.Default.ParseArguments <AddWordCommand, RemoveWordCommand, FindWordCommand>(args)
                .WithParsed <AddWordCommand>(o => AddWordCommand.AddWord(o, words))
                .WithParsed <RemoveWordCommand>(o => RemoveWordCommand.RemoveWord(o, words))
                .WithParsed <FindWordCommand>(o => FindWordCommand.FindWords(o, words));
            }
        }