From 691f9153e9698bbc18247b043bb5cad04f52dc20 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 25 Nov 2021 22:58:08 +0200 Subject: [PATCH] fix: bug with "NumberDifferentVowelsInLine" --- Lab4.K2/Program.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lab4.K2/Program.cs b/Lab4.K2/Program.cs index 7667f33..9fc4fce 100644 --- a/Lab4.K2/Program.cs +++ b/Lab4.K2/Program.cs @@ -14,9 +14,16 @@ namespace Lab4.K2 public static int NumberDifferentVowelsInLine(string line) { - string vowels = "AEIYOUaeiyouĄąĘęĖėĮįŲųŪū"; - string pattern = string.Format(@"[{0}]", Regex.Escape(vowels)); - return Regex.Matches(line, pattern).Count; + string vowels = "aeiyouąęėįųū"; + int count = 0; + + line = line.ToLower(); + foreach (char vowel in vowels) + { + count += line.Contains(vowel) ? 1 : 0; + } + + return count; } // Note: returns words including punctuation after them