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
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
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
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384