How to remove the last line in a RichTextBox

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
 
M

Master Programmer

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
 
R

RobinS

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.
 
F

Franky

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
 
F

Franky

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top