public static IEnumerable <string> ReplaceBadWordsWithGoodWords(string path) { var words = FileParser.ReplaceBadWordsWithGoodWordsImpl(); var file = new List <string>(); using (StreamReader streamReader = new StreamReader(path)) { while (streamReader.Peek() >= 0) { string line = streamReader.ReadLine(); foreach (var word in words) { line = line.Replace(word.Key, word.Value); } file.Add(line); } } return(file); }
public static int CountWord(string path) { var wordsDictionary = FileParser.ReplaceBadWordsWithGoodWordsImpl(); int count = 0; foreach (string line in File.ReadAllLines(path)) { var words = line.Split(); foreach (string word in words) { foreach (var item in wordsDictionary) { if (Regex.IsMatch(word, item.Key)) { count++; } } } } return(count); }