blah blah blah is here! blah blah » Close

up1down
link

hello

i want to delete the last line in RichTextBox1

last answered one year ago

1 answers

link

The following code should do it:

// get rid of any whitespace at the end
richTextBox1.Text = richTextBox1.Text.TrimEnd(' ', '\r', '\n', '\t');
// find length of remaining text
int length = richTextBox1.Text.Length;
if (length > 0)
{
// get physical line number of last character
int lastLine = richTextBox1.GetLineFromCharIndex(length - 1);
// get character index of first character on that line
int firstIndex = richTextBox1.GetFirstCharIndexFromLine(lastLine);
// remove characters on last line
richTextBox1.Text = richTextBox1.Text.Substring(0, firstIndex);
}

king_888
153

thank you

Feedback