Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 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 15-Sep-20 10:33am

1 solution

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)
VB
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!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900