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

Textbox1.Text =

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"

lines dani knows everything
web knows lines
dani everything lines
6 Years
Discussion Span
Last Post by vb2learn

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
        Return sTemp '// return text back to TextBox.
    End Function
End Class
Votes + Comments
Very nice and helpful post by codeorder

Thank You debasisdas

But the example by codeorder worked.

Thank You Codeorder.

Marked As Resolved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.