I have a TextBox and want to delete lines if line before = line after.
I have Text like that:
Ab cd ...
Ef Gss ...
EE oo ...
EE oo ... // delete this line
qq ss ff
ok ee ..
I tried with many codes but it removed me all same lines. I just want to remove next same line. Empty lines should be always there.
Code I used:
richTextBox1.Text = string.Join( Environment.NewLine, richTextBox1.Lines.Distinct());
Or:
for (int tx = 0; tx < richTextBox1.Text.Length; tx++)
{
for (int tx1 = tx + 1; tx1 < richTextBox1.Text.Length; tx1++)
{
if (richTextBox1.Lines[tx] == richTextBox1.Lines[tx1])
// something like richTextBox1.Lines[tx1].RemoveAt(tx1);
}
}
Try this –