VB .NET Duplicate a specific line in a textbox?

I want to search for text containing a specific string and duplicate the line containing the string under it.

EG: I search for the word: "Test" in a textbox that contains the following:

Hello
Test
Example

And it finds the word Test on Line 2 and duplicates it. The end result should be this.

Hello
Test
Test
Example

Does anyone have any idea how to do this?
Maximus1001Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rgn2121Connect With a Mentor Commented:
This could be improved and will need a little more testing, but works.  It took your original items from Textbox1 and placed the new result in Textbox2.  This assumes that the items in Textbox1 were separated by carriage returns.
 
Didn't really do much error checking.  Also, I only used the comparison for a static string object for simplicity...

        Dim temp() As String
        temp = TextBox1.Text.Split(ChrW(13))

        For i As Integer = 0 To temp.Length - 1
            If temp(i).ToString.Trim = "Test" Then
                'String and index found...
                TextBox2.Text += temp(i).ToString & Environment.NewLine
                TextBox2.Text += temp(i).ToString & Environment.NewLine
            Else
                'string not found...add to new textbox
                TextBox2.Text += temp(i).ToString & Environment.NewLine
            End If

        Next

Open in new window

0
 
Amandeep Singh BhullarCommented:
can you share the code that searches the text.
0
 
Maximus1001Author Commented:
Worked perfect, thanks!
0
All Courses

From novice to tech pro — start learning today.