This Unit Test
[TestCase(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"ipsum\namet\neuysmod\nlabore\naliqua",
ExpectedResult = "Lorem dolor sit , consectetur adipiscing elit, sed do eiusmod tempor incididunt ut et dolore magna .")]
public static void RemoveWordsFromContentAndWrite(StreamReader contentReader, StreamReader wordsReader, StreamWriter outputWriter)
{
// TODO #5-5. Implement the method by reading the content and words, removing words from the content, and writing the updated content to the outputWriter. Use StreamReader.Peek method for checking whether there are more characters in the underlying string.
var words = wordsReader.ReadToEnd();
var bufferSize = 100;
var buffer = new char[bufferSize];
var bytesCount = 0;
var currentWord = new StringBuilder();
while ((bytesCount = contentReader.ReadBlock(buffer, 0, bufferSize)) > 0)
{
for (var i = 0; i < bytesCount; i++)
{
if (char.IsLetterOrDigit(buffer[i]))
{
currentWord.Append(buffer[i]);
}
else
{
if (!words.Contains(currentWord.ToString()))
{
outputWriter.Write(currentWord);
}
outputWriter.Write(buffer[i]);
currentWord.Clear();
}
}
outputWriter.Flush();
}
if (!string.IsNullOrEmpty(currentWord.ToString()) && !words.Contains(currentWord.ToString()))
{
outputWriter.Write(currentWord);
outputWriter.Flush();
}
}