I'm trying to check if large text document about 500 000 lines contains specific line, and problem is if I find it this way:
string searchLine = "line 4";
using (StreamReader sr = new StreamReader(filePath))
{
string contents = sr.ReadToEnd();
if (contents.Contains(searchLine))
{
Console.WriteLine("line exist");
}
else
{
Console.WriteLine("line does not exist");
}
}
and document content is and I do not accept writing duplicates to it, all string are unique:
line 1
line 2
line 3
line 4
line 5
line 47
So I got answer that's "line exist" for "line 4" right, but then if I remove it from the order, and check file for same string "line 4" again, it says that the "line exist", because seems like it founds all 4 numbers in text file content, and only if I remove "line47", then "line does not exist".
So I'm wondering how to find specific line with unique string content in large text document.