Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read and delete lines
#1
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!
#2
Sorry, forgot to enter some extra info:
- I want to delete a line that contains a part of a text
#3
Are you referring to a sentence? Or an entire line?
My Blog | My Setup | My Videos | Have a wonderful day.
#4
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.
#5
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!
My Blog | My Setup | My Videos | Have a wonderful day.
#6
Ah thanks! Needed this a lot <!-- s:mrgreen: --><img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green" /><!-- s:mrgreen: -->
#7
brco900033 Wrote:Ah thanks! Needed this a lot <!-- s:mrgreen: --><img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green" /><!-- s:mrgreen: -->
No problemo!
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 33,039 04-12-2013, 06:27 PM
Last Post: brandonio21
  Convert 2 lines to one brco900033 2 11,916 02-23-2013, 11:04 AM
Last Post: brco900033
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,859 11-28-2012, 05:19 PM
Last Post: brandonio21
  Read certain lines brco900033 3 14,635 09-26-2012, 03:56 PM
Last Post: brandonio21
  How to write string query on multiple lines kismetgerald 1 8,960 08-29-2012, 04:01 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)