RobertoFreemano
asked on
Remove 2 lines from a textbox (VB.NET)
Hi Experts,
My WinForm as a Textbox(multi-line) and a Button.
The data in the Textbox is as follows: e.g.
1: Static String
2: Rand String
3: Rand String
4: Rand String
5: Static String
The Static String Lines never change.. so I want to only keep the Rand String and remove line 1 & 5. Lines 1 & 5 are not same line of text either.
I searched the web looking for examples and this one was close but not quite what I had in mind.
So, search textbox for "specific line of text?", then remove it. and also copy all leftover text to clipboard ;)
Thanks,
Roberto
My WinForm as a Textbox(multi-line) and a Button.
The data in the Textbox is as follows: e.g.
1: Static String
2: Rand String
3: Rand String
4: Rand String
5: Static String
The Static String Lines never change.. so I want to only keep the Rand String and remove line 1 & 5. Lines 1 & 5 are not same line of text either.
I searched the web looking for examples and this one was close but not quite what I had in mind.
TextBox1.Lines = New String() _
{"somethingt", "something else"}
Dim a As String() = TextBox1.Lines
Dim b(TextBox1.Lines.Length - 1) As String
TextBox1.Clear()
For i As Integer = 1 To a.Length - 1
b(i - 1) = a(i)
Next
TextBox1.Lines = b
So, search textbox for "specific line of text?", then remove it. and also copy all leftover text to clipboard ;)
Thanks,
Roberto
ASKER
This works
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If TextBox1.Text.Contains("This is an example1") Then
TextBox1.Text = TextBox1.Text.Replace("This is an example1", " ")
ElseIf TextBox1.Text.Contains("This is an example2") Then
TextBox1.Text = TextBox1.Text.Replace("This is an example2", " ")
End If
End Sub
But it takes two button clicks to achieve it... I want one click action.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
But there's an issue after AND...