Click here to Skip to main content
14,635,494 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All!

Complete noob trying to grasp some basic concepts.

Working with VB in Visual Studio.

How can I search for terms, defined in RichTextBox1, and print lines that have those terms from RichTextBox2 into RichTextBox3?

What I have tried:

If RichTextBox1.Contains(RichTextBox2.Text) Then

...that's actually as far as I've gotten.
Posted
Updated 4 days ago

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Would suggest you to start from here: RichTextBox.Find Method (System.Windows.Forms) | Microsoft Docs[^]

Reference example (not exactly you need, i.e. print per line part)
Public Function FindMyText(ByVal searchText As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = -1

    ' Ensure that a search string and a valid starting point are specified.
    If searchText.Length > 0 And searchStart >= 0 Then
        ' Ensure that a valid ending value is provided.
        If searchEnd > searchStart Or searchEnd = -1 Then
            ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase)
            ' Determine whether the text was found in richTextBox1.
            If indexToText >= 0 Then
                ' Return the index to the specified search text.
                returnValue = indexToText
            End If
        End If
    End If

    Return returnValue
End Function

Try out!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100