I have a program that will write to a text file if recognition engine recognize any word in the keywords[]. However i want to check if the .txt file already contains (ts.Hours + ts.Minutes + ts.Seconds) , the current timespan already exists in the file. I do not want to write to it because i dont want an output with the same timespan like 5 times in a row.. so the way to fix this is to read the file first and check if that value already contains. However now i am stuck. I cant get around having the streamwriter inside the streamreader. is there anyway i can do this?
foreach (string x in keywords)
{
using (var reader = new StreamReader(pathToTextFile))
{
if (e.PartialResult.ToLower().Contains(x))
{
while ((line = reader.ReadLine()) != ts.Hours.ToString() + ts.Minutes.ToString() + ts.Seconds.ToString())
{
//reader.Close(); This line will allow me to write to the text file but when it loops up again it cant read from a closed reader.
using (StreamWriter sw = File.AppendText(string.Format(textBox1.Text + @"\SpyTrouble Logs\Keywords {0} {1}-{2}.txt", Environment.UserName, now.Day, now.Month)))
{
string elapsedTime = string.Format("{0:00}:{1:00}:{2:00} Found keyword here", ts.Hours, ts.Minutes, ts.Seconds);
sw.WriteLine(elapsedTime);
}
}
}
}
}