1
0

fix: bug in "FindWord1Line"

This commit is contained in:
Rokas Puzonas 2021-11-25 23:53:48 +02:00
parent 691f9153e9
commit d2c1a49ebb

View File

@ -29,33 +29,40 @@ namespace Lab4.K2
// Note: returns words including punctuation after them // Note: returns words including punctuation after them
public static MatchCollection MatchByWords(string line, string punctuation) public static MatchCollection MatchByWords(string line, string punctuation)
{ {
string pattern = string.Format(@"[^{0}]+[{0}]*", Regex.Escape(punctuation)); string pattern = string.Format(@"([^{0}]+)[{0}]*", Regex.Escape(punctuation));
return Regex.Matches(line, pattern); return Regex.Matches(line, pattern);
} }
public static string FindWord1Line(string line, string punctuation) public static string FindWord1Line(string line, string punctuation)
{ {
List<string> wordsWith3Vowels = new List<string>(); List<Match> wordsWith3Vowels = new List<Match>();
foreach (Match match in MatchByWords(line, punctuation)) foreach (Match match in MatchByWords(line, punctuation))
{ {
int vowelCount = NumberDifferentVowelsInLine(match.Value); int vowelCount = NumberDifferentVowelsInLine(match.Value);
if (vowelCount == 3) if (vowelCount == 3)
{ {
wordsWith3Vowels.Add(match.Value); wordsWith3Vowels.Add(match);
} }
} }
string longestWord = ""; Match longestWord = null;
foreach (string word in wordsWith3Vowels) foreach (Match word in wordsWith3Vowels)
{ {
if (word.Length > longestWord.Length) if (word.Groups[1].Length > longestWord.Groups[1].Length)
{ {
longestWord = word; longestWord = word;
} }
} }
return longestWord; if (longestWord == null)
{
return "";
}
else
{
return longestWord.Value;
}
} }
public static string EditLine(string line, string punctuation, string word) public static string EditLine(string line, string punctuation, string word)