Delete a specific line in a .NET RichTextBox

后端 未结 9 1532
后悔当初
后悔当初 2021-01-19 15:08

How can I delete a specific line of text in a RichTextBox ?

9条回答
  •  遥遥无期
    2021-01-19 15:36

    Lots of good answers, but I find many far to complicated.

    string[] LinesArray = this.richTextBox1.Lines;
    
    this.richTextBox1.Clear();
    
    for (int line = 0; line < LinesArray.Length; line++)
    {
    if (!LinesArray[line].Contains("< Test Text To Remove >"))
    {
    this.richTextBox1.AppendText(LinesArray[line] + Environment.NewLine);
    }
    }
    

    I hope this helps others some ;0)

提交回复
热议问题