Page 1 of 1

Search and delete

Posted: Sun Jun 08, 2014 7:58 pm
by Dummy1912
hello,

can anyone help me with a richtextbox

i want only the lines that contains a string word

for example:

hello how are you today bruno
o hej we doing fine
who's bruno?
we have no idea

so then i only want the lines that contains bruno
to show in a string.

so that i only have those 2 lines left
hello how are you today bruno
who's bruno?


anyone?

thanks

Re: Search and delete

Posted: Sun Jun 08, 2014 8:29 pm
by comathi
This worked for me, I hope it's what you're looking for :)
Code: Select all
 Dim lines() As String
        Dim count As Integer

        For i = 0 To RichTextBox1.Lines.Count - 1
            If RichTextBox1.Lines(i).Contains("bruno") Then
                ReDim Preserve lines(count)

                lines(count) = RichTextBox1.Lines(i)

                count += 1
            End If
        Next

        RichTextBox1.Clear()

        If lines.Count > 0 Then
            For i = 0 To lines.Count - 1
                RichTextBox1.AppendText(lines(i))

                If i < lines.Count Then RichTextBox1.AppendText(vbNewLine)
            Next
        End If

Re: Search and delete

Posted: Sun Jun 08, 2014 10:05 pm
by Dummy1912
clapper; nice job
yes this is the part we looking for

thank you so much #comathi loove;

+rep