It's difficult to work out exactly what that code is supposed to do, but it's somewhat muddled at best.
You are adding each line you read to TextLine, regardless of what it contains:
Textline = Textline + ObjReader.ReadLine();
You then check that to see if contains a value:
if (Textline.Contains(flag) == true)
If it does, you loop through each character in an unrelated and unchanging string:
for (int i = 0; i < txtInput.Lines.Length; i++)
And ... do nothing with it:
{
}
If it doesn't, you set the output to a "Not Found" message, but showing somethgin your didn't search for:
lblOutput.Text = txtInput.Text + " : NOT FOUND";
And then you go round and to it again for the next line!
If you are trying to find a line that contains a specific value, then sit down and think about it:
1) Set a flag to say "not found".
2) Loop through each line
2.1) If the line contains the text then
2.1.1) Set the "found flag"
2.1.2) Save the line
2.1.3) Exit the loop (hint:
break
is handy here)
3) After the loop, check the "found" flag
3.1 If it's set, show the line
3.2 If it's still "not found", report an error.
Me? I'd use
File.ReadAllLines[
^] and then use a
foreach
loop to make it easier to read.