Beispiel #1
0
 private static void ShowResults(CounterOfVowelsLetters counter, string text)
 {
     foreach (var letter in counter.GetResult(text))
     {
         Console.WriteLine("{0}: {1}", letter.Key, letter.Value);
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            bool splitToWords = false;
            string answer;
            int minLength = 0, maxLength = 0;
            do
            {
                Console.Write("Set the maximum and minimum length of words to be scanned? (Yes|No): ");

                answer = Console.ReadLine().ToLower();
                if (answer == "yes")
                {
                    splitToWords = true;

                    minLength = int.Parse(EstablishValue("minimal"));
                    maxLength = int.Parse(EstablishValue("maximal"));
                    if(minLength > maxLength) Swap(ref minLength, ref maxLength);
                }
            } while (answer != "yes" && answer != "no");

            IReader reader = new ReaderFromTxt(@"text.txt");
            string text = reader.Read();

            var counter = new CounterOfVowelsLetters();

            if (splitToWords)
            {
                Separator separator = new Separator();
                var words = separator.GetListOfWords(text);

                foreach (var word in words)
                {
                    if (word.Length >= minLength && word.Length <= maxLength)
                    {
                        counter.Count(word);
                    }
                }
            }
            else counter.Count(text);

            ShowResults(counter, text);

            Console.ReadKey();
        }