Posts: 96
	Threads: 39
	Joined: Sep 2011
	
Reputation: 
0
	 
	
	
		Hello guys
I have a question; how can I read and delete a specific line from a textbox (multiline already set to true ofcourse). I searched a lot of forums but those codes always contains little errors.
Have a nice day!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 96
	Threads: 39
	Joined: Sep 2011
	
Reputation: 
0
	 
	
	
		Sorry, forgot to enter some extra info:
 - I want to delete a line that contains a part of a text
	
	
	
	
	
 
 
	
	
	
		
	Posts: 1,006
	Threads: 111
	Joined: Jul 2010
	
Reputation: 
1
	 
	
	
		Are you referring to a sentence? Or an entire line?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 96
	Threads: 39
	Joined: Sep 2011
	
Reputation: 
0
	 
	
	
		A line.
For example:
-the textbox contains:
I live in belgium
my name is brco
I'm 15 years old
...
-I search for 'My name'
-the second line contains 'my name' so that whole line will be deleted.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 1,006
	Threads: 111
	Joined: Jul 2010
	
Reputation: 
1
	 
	
	
		Ah, alright! Well this solution is rather fancy, if I don't say so myself.
So, I have created this method that completely removes a line from the textbox which contains a specified value. 
[code2=vbnet]Public Sub RemoveLine(ByVal containing As String)
        If (TextBox1.Text.Contains(containing)) Then
            'Now, we need to find which line index contains the thing
            Dim lineIndex As Integer = TextBox1.GetLineFromCharIndex(TextBox1.Text.IndexOf(containing))
            'Now, let's delete that line
            Dim lines As New List(Of String)
            lines.AddRange(TextBox1.Text.Split(vbNewLine))
            lines.RemoveAt(lineIndex)
            'Now, reset the text
            TextBox1.Text = String.Join(vbNewLine, lines.ToArray, 0, lines.Count)
        End If
    End Sub[/code2]
So, if you want to delete a line containing whatever TextBox2.Text has in it, for example, add a button to your form (Button1), then, just call this code from your button:
[code2=vbnet]RemoveLine(TextBox2.Text)[/code2]
Hopefully this works for you!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 96
	Threads: 39
	Joined: Sep 2011
	
Reputation: 
0
	 
	
	
		Ah thanks! Needed this a lot <!-- s:mrgreen: --><img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green" /><!-- s:mrgreen: -->