コード例 #1
0
        static void Main(string[] args)
        {
            StringsFile.CreateFileIfNotExist();
            WordsDicionary wordsDictionary = new WordsDicionary(StringsFile.ReadLines());

            Console.Write("Search for a word (5 alphnumeric characters) >> ");
            string word = Console.ReadLine();

            while (word != "exit") //change to string compaee
            {
                if (word.Length != 5)
                {
                    Console.WriteLine("Word's length must be exactly 5 alphanumerical characters!");
                }
                else if (!r.IsMatch(word))
                {
                    Console.WriteLine("Word must contains alphanumerical characters only!");
                }
                else
                {
                    int    matchesCnt = wordsDictionary.FindMathces(word);
                    string matchStr   = matchesCnt == 0 ? "was not found in file." : $"was found in the file {matchesCnt} times.";
                    Console.WriteLine($"Word \"{word}\" (or equivalents) {matchStr}");
                }

                Console.Write("Search for a word (5 alphnumeric characters) >> ");
                word = Console.ReadLine();
            }
        }
コード例 #2
0
ファイル: WordsDictionaryTest.cs プロジェクト: malkag/Brix
        public void WordsDictionary_Test()
        {
            WordsDicionary wordsDictionary = new WordsDicionary(new string[] { "AaBb1", "abAB1", "A1abB", "123fR", "R1F23", "zzzXX" });

            Assert.AreEqual(wordsDictionary.FindMathces("AaBb1"), 3);
            Assert.AreEqual(wordsDictionary.FindMathces("1aAbB"), 3);

            Assert.AreEqual(wordsDictionary.FindMathces("123fR"), 1);

            Assert.AreEqual(wordsDictionary.FindMathces("xxZZZ"), 0);
            Assert.AreEqual(wordsDictionary.FindMathces("zXzXz"), 1);
        }