Hello Coders
Need help
I want to remove the lines that contain specific text. (Whole Line)

Eg:
Textbox1.Text =

learn
lines dani knows everything
web knows lines
lines knows daniweb everything
dani everything lines

So textbox1.text will become and remove whole line that contains the word "daniweb"

learn
lines dani knows everything
web knows lines
dani everything lines

1. find the position of the word that you are looking for.
2. find the position of the previous and next new line character.
3. delete / remove everything in between.

4. go to step 1

See if this helps to remove certain lines from a TextBox.

Public Class Form1
    Private arTemp() As String = Nothing '// used to get all lines from TextBox.
    Private sTemp As String = Nothing '// used to add lines back to TextBox.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '//------------- removeLines(text in line to locate, TextBox to search for text)
        TextBox1.Text = removeLines("daniweb", TextBox1)
    End Sub

    Private Function removeLines(ByVal textInLineToFind As String, ByVal selectedTextBox As TextBox) As String
        arTemp = selectedTextBox.Lines '// set all lines from TextBox into a String Array.
        sTemp = "" '// clear for new input.
        For Each txtLine As String In arTemp '// loop thru all arrays.
            If Not txtLine.Contains(textInLineToFind) Then '// check for line that contains preselected text and skip if .Contains.
                '// if not in line, add to string.
                If Not sTemp = "" Then sTemp &= vbNewLine & txtLine Else sTemp = txtLine
            End If
        Next
        Return sTemp '// return text back to TextBox.
    End Function
End Class
commented: Very nice and helpful post by codeorder +1

Thank You debasisdas

But the example by codeorder worked.

Thank You Codeorder.

Marked As Resolved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.