删除富文本框的最后一行?

use*_*565 0 c# regex stringbuilder substring

我喜欢删除以 ; 结尾的 richtextbox 的最后一行。半柱。我喜欢删除这一行,直到;最后一个半列之前的半列。

例子:

hello do not delete this line;
hello this sentence will continue...
untill here;
Run Code Online (Sandbox Code Playgroud)

结果应该是:

hello do not delete this line;
Run Code Online (Sandbox Code Playgroud)

我的代码:

private void button1_Click_1(object sender, EventArgs e) {
        List<string> myList = richTextBox1.Lines.ToList();
        if (myList.Count > 0) {
            myList.RemoveAt(myList.Count - 1);
            richTextBox1.Lines = myList.ToArray();
            richTextBox1.Refresh();
        }
    }
Run Code Online (Sandbox Code Playgroud)

小智 5

在这里找到了解决方案:

RichTextBox1.Lines = RichTextBox1.Lines.Take(RichTextBox1.Lines.Length - 3).ToArray();
Run Code Online (Sandbox Code Playgroud)