0

How to delete number of lines from richDataTextBox? I need to delete each second line. For example, I have a text document, opened in rich DataTextBox..

1. "aaaaaaa  
     bbbbbbb  
     ccccccc  
     ddddddd"

How can I delete lines: "bbbbbbb" and "ddddddd"... and continue till the end of the text file.

var lines = this.dataTextBox.Lines;
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
user922907
  • 539
  • 2
  • 8
  • 18

1 Answers1

3

You can use LINQ to delete every second line:

var lines=richTextBox1.Lines
    . Where((l, index) => index % 2 == 0)
    .Select((l, index) => l);
richTextBox1.Lines = lines.ToArray();

It selects all lines that should not be deleted and skips all others.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thank You very much. Exactly, what I need. (I'm still not strong in syntax.) I like to use LINQ. It is perfect for me! – user922907 Feb 23 '12 at 08:16