How to remove the last line in a RichTextBox

  • Thread starter Thread starter Franky
  • Start date Start date
F

Franky

What I want to do is delete the last line in a RichTextBox.

The RichTextBox has a ReadOnly property called lines that seems like it
might help but I cant figure out how to use it.

Well, the question is what is the easiest way to remove the last line in a
RichTextBox?

Thanks
 
Hi

The easiest way is to move the cursor to the beginning of the desired
line. Next hold down the delete key until all characters have been
removed.

Hope this helps.
The Grand Master
 
I don't know about the [lines] property, but assuming that each
line in the RichTextBox has a carriageReturn/LineFeed combination
at the end of it, this should work.

Private Sub RemoveLastLine()
Dim myData() As String
Dim crlfs() As String = {ControlChars.CrLf}
Dim lines As String = myRichTextBox.Text
'split it by crlf
myData = lines.Split(crlfs, StringSplitOptions.None)
're-join it without the last line
Dim outputString As String = _
String.Join(ControlChars.CrLf, myData, 0, myData.Length - 1)
myRichTextBox.Text = outputString
End Sub

Robin S.
 
Thanks but my fault, I meant programmatically


Master Programmer said:
Hi

The easiest way is to move the cursor to the beginning of the desired
line. Next hold down the delete key until all characters have been
removed.

Hope this helps.
The Grand Master
 
Thanks, that looks good.

RobinS said:
I don't know about the [lines] property, but assuming that each
line in the RichTextBox has a carriageReturn/LineFeed combination
at the end of it, this should work.

Private Sub RemoveLastLine()
Dim myData() As String
Dim crlfs() As String = {ControlChars.CrLf}
Dim lines As String = myRichTextBox.Text
'split it by crlf
myData = lines.Split(crlfs, StringSplitOptions.None)
're-join it without the last line
Dim outputString As String = _
String.Join(ControlChars.CrLf, myData, 0, myData.Length - 1)
myRichTextBox.Text = outputString
End Sub

Robin S.
---------------------------------
Franky said:
What I want to do is delete the last line in a RichTextBox.

The RichTextBox has a ReadOnly property called lines that seems like it
might help but I cant figure out how to use it.

Well, the question is what is the easiest way to remove the last line in
a RichTextBox?

Thanks
 
Back
Top