Home All Groups Group Topic Archive Search About

How to remove the last line in a RichTextBox

Author
20 Nov 2006 7:22 PM
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

Author
21 Nov 2006 6:02 AM
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

Franky wrote:
Show quoteHide quote
> 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
Author
21 Nov 2006 3:46 PM
Franky
Thanks but my fault, I meant programmatically


Show quoteHide quote
"Master Programmer" <master_program***@outgun.com> wrote in message
news:1164088928.379830.167610@e3g2000cwe.googlegroups.com...
> 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
>
> Franky wrote:
>> 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
>
Author
21 Nov 2006 8:20 AM
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.
---------------------------------
Show quoteHide quote
" Franky" <frankyNOSPAM@a-znet.com> wrote in message
news:eaWF2kNDHHA.4372@TK2MSFTNGP03.phx.gbl...
> 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
>
>
>
>
>
Author
21 Nov 2006 3:51 PM
Franky
Thanks, that looks good.

Show quoteHide quote
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:9pOdnUIAUMdIK__YnZ2dnUVZ_oidnZ2d@comcast.com...
>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" <frankyNOSPAM@a-znet.com> wrote in message
> news:eaWF2kNDHHA.4372@TK2MSFTNGP03.phx.gbl...
>> 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
>>
>>
>>
>>
>>
>
>