5 Replies - 427 Views - Last Post: 10 February 2012 - 06:47 AM Rate Topic: -----

Topic Sponsor:

#1 jamiewright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 12

Removing sections of richtectbox vb.net

Posted 08 February 2012 - 05:55 AM

I currently have a section of code that downloads html and puts it into a richtectbox so that i can edit it and remove sections of code that i want (Stock market values) currently i have used a regex function to remove html tags and i have a saved text file that is read and each entry is then removed from the richtextbox but this wont work for all of it as the data is constantly changing. I have looked alot on the internet and i cant find a way to remove say lines 1 to 50 of the rich text box. I know the rich textbox has index lines

Here is my current remove code but that only removes pre-set strings -
Do

            RichTextBox1.Text = R.Replace(RichTextBox1.Text, "")
            line_input = text_input.ReadLine

            If line_input <> Nothing Then
                words1(counter) = line_input
            End If
            counter = counter + 1
        Loop Until line_input = Nothing
        number_of_words = counter - 1
        For counter = 0 To number_of_words - 1
            Do
                search1 = InStr(RichTextBox1.Text, words1(counter))
                If search1 <> 0 Then
                    If search1 <> Nothing Then
                        If search1 Then

                            RichTextBox1.Focus()
                            RichTextBox1.Selectionstart = search1 - 1
                            RichTextBox1.SelectionLength = Len(words1(counter))
                            Me.RichTextBox1.SelectedText = ""

                        End If
                    End If
                End If

            Loop Until search1 = Nothing Or search1 = 0
        Next 


I have experimented with removing enter (next line) using their ascii values but i couldnt get anywhere.

Im not looking for someone to make my code for me but i know what i am doing and i have friends who are also good at vb.net i just need to know the function type and how it works and i can do the rest.

Is This A Good Question/Topic? 0
  • +

Replies To: Removing sections of richtectbox vb.net

#2 Ionut  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 327
  • View blog
  • Posts: 914
  • Joined: 17-July 10

Re: Removing sections of richtectbox vb.net

Posted 08 February 2012 - 10:37 PM

Take a look at substring methods and apply them to Text property of richtextbox.
Here all methods of the string class.
Was This Post Helpful? 0
  • +
  • -

#3 DimitriV  Icon User is offline

  • It's been so long, without this feeling
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,533
  • Joined: 24-July 11

Re: Removing sections of richtectbox vb.net

Posted 09 February 2012 - 12:40 AM

You want to remove the first 50 lines? Use this:
For line As Integer = 0 To 49 'because 0 is item 1 in arrays
RichTextBox1.Lines.Remove(line)
Next


It's a very basic example, it's going to get rid of the first 50 lines in the RTB. This should suit you, but if you've got any issues post.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • Coder-ian
  • member icon

Reputation: 1401
  • View blog
  • Posts: 7,361
  • Joined: 29-May 08

Re: Removing sections of richtectbox vb.net

Posted 09 February 2012 - 01:45 AM

View PostjimmyBo, on 09 February 2012 - 08:40 AM, said:

You want to remove the first 50 lines? Use this:
For line As Integer = 0 To 49 'because 0 is item 1 in arrays
RichTextBox1.Lines.Remove(line)
Next


It's a very basic example, it's going to get rid of the first 50 lines in the RTB. This should suit you, but if you've got any issues post.


If you remove the first (0) than then the next line, doesn't that make the next line also the first line also?
Was This Post Helpful? 0
  • +
  • -

#5 jamiewright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 12

Re: Removing sections of richtectbox vb.net

Posted 10 February 2012 - 02:45 AM

View PostjimmyBo, on 09 February 2012 - 12:40 AM, said:

You want to remove the first 50 lines? Use this:
For line As Integer = 0 To 49 'because 0 is item 1 in arrays
RichTextBox1.Lines.Remove(line)
Next


It's a very basic example, it's going to get rid of the first 50 lines in the RTB. This should suit you, but if you've got any issues post.


For me this returns and error as .remove isnt a part of the system array. I tried -
For line = 0 To 49 'because 0 is item 1 in arrays
            RichTextBox1.Lines(line) = R.Replace(RichTextBox1.Lines(line), "")
        Next


This only puts the cursor onto the 50th line but doesnt remove it. I have tried a few other things but they are for deleting strings not lines
 For line As Integer = 0 To 49 'because 0 is item 1 in arrays
            RichTextBox1.Lines(line) = String.Empty
        Next

I used
RichTextBox1.Focus()
                me.richtextbox1.selectedtext = ""
This just remove everything and then crashed.
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 960
  • View blog
  • Posts: 3,354
  • Joined: 25-September 09

Re: Removing sections of richtectbox vb.net

Posted 10 February 2012 - 06:47 AM

One way you should be able to achieve this is to loop through the first 50 lines and select them and then perform a .Cut operation on the rtb.

It's not elegant but I think it would work.
    Private Sub btnDeleteRows_Click(sender As System.Object, e As System.EventArgs) Handles btnDeleteRows.Click
        For x As Integer = 0 To 49 'Of course this is the first 50 lines
            rtb.Selectionstart = 0 'Start your selection at position 0 of the rtb text
            'Select each line by increasing
            'the selection length for each
            'line length +1 to get the newline char.
            rtb.SelectionLength += rtb.Lines(x).Length + 1
        Next x
        'Now that you have the first 50 rows selected perform a .Cut
        rtb.Cut()
        'Optional, clear the clipboard.
        Clipboard.Clear()
    End Sub

This post has been edited by CharlieMay: 10 February 2012 - 06:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1