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:


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


Does anyone have any idea how to do this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amandeep Singh BhullarCommented:
can you share the code that searches the text.
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
                'string not found...add to new textbox
                TextBox2.Text += temp(i).ToString & Environment.NewLine
            End If


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maximus1001Author Commented:
Worked perfect, thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.