string path = "xx\\xx.txt";
string[] memo = System.IO.File.ReadAllLines(path);
int totalLines = textBox2.Lines.Length;
string lastLine = textBox2.Lines[totalLines - 1];
for (int i = 0; i < 5; i++)
{
string a = memo[i];
if (a.Contains(lastLine))
{
textBox2.Text = (textBox2.Text + Environment.NewLine + memo[i + 1]);
}
}
Check the notepad from lines 0 to 4
if (a.Contains(lastLine))
{
textBox2.Text = (textBox2.Text + Environment.NewLine + memo[i + 1]);
}
I want to make above code run only once.
However, because there is a memo[i+1]
variable i
.
Under the influence of the for statement that repeats 5 times, the text 5 times is input.
How can I fix it?