How to read the last line in a textbox?

后端 未结 3 811
花落未央
花落未央 2021-01-13 03:57

I have a multiline textbox that constantly gets updated. I need to read only the last word/sentence in the textbox.

string lastLine = textBox1.ReadLine.Last(         


        
3条回答
  •  有刺的猬
    2021-01-13 04:15

    Try this:

    if (textBox1.Lines.Any())
    {
        string lastLine = textBox1.Lines[textBox1.Lines.Length - 1];
    }
    

    And for last word:

    string lastword = lastLine.Split(' ').Last();
    

提交回复
热议问题