So you are starting with:
I assume that you wanted to know whether I can tell you about Wales.
I assume that you wanted to know whether I can tell you about Wales.
whether I can tell you about Wales
Wales is an administrative division in the UK.
Wales
an administrative division
the UK
Source: START KB
Source:
Go back to the START dialog window.
Go back to the START dialog window.
Go back to the START dialog window.
and you want to end up with:
I assume that you wanted to know whether I can tell you about Wales.
whether I can tell you about Wales
Wales is an administrative division in the UK.
Wales
an administrative division
the UK
Source: START KB
Source:
Go back to the START dialog window.
or, do you want to end up with:
I assume that you wanted to know whether I can tell you about Wales.
Wales is an administrative division in the UK.
Source: START KB
Go back to the START dialog window.
If it is the former then it is a simple as:
' Get the content of the file into a List(Of String).
Dim _list = New List(Of String)(File.ReadAllLines("C:\answer.txt"))
' Read the list from the bottom up but do not process the first line.
For _i = _list.count - 1 To 1 Step - 1
' If the line above (_i - 1) the line of interest (_i) is the equivalent
value then remove the line of interest.
If _list(_i - 1) = _List(_i) Then _list.RemoveAt(_i)
Next
' Join the lines together NewLines and put the result in the textbox.
TextBox1.Text = String.Join(Environment.Newline, _list.ToArray())
If it is the latter, then the solution is more complex because you need to
consider parts of lines rather than whole lines. To do this you need to read
from the top down and when you remove a line you need to start a new pass
over the whole list.
' Get the content of the file into a List(Of String).
Dim _list = New List(Of String)(File.ReadAllLines("C:\answer.txt"))
Dim _removal = True
While _removal
_removals = False
' Read the list from the top down starting from line 2.
For _i = 1 To _list.Count - 1
' If the line above (_i - 1) the line of interest (_i) contains the
value of interest then remove the line of interest and start a new pass.
If _list(_i - 1).Contains(_List(_i)) Then
_list.RemoveAt(_i)
_removal = True
Next
End While
' Join the lines together NewLines and put the result in the textbox.
TextBox1.Text = String.Join(Environment.Newline, _list.ToArray())
The first pass will remove the second occurrence of:
I assume that you wanted to know whether I can tell you about Wales.
The second pass will remove:
whether I can tell you about Wales
The third pass will remove:
Wales
The fourth pass will remove:
an administrative division
The fifth pass will remove:
the UK
The sixth pass will remove:
Source:
The seventh pass will remove the second occurrence of:
Go back to the START dialog window.
The eighth pass will remove the second occurrence of:
Go back to the START dialog window.
<kr*******@yahoo.co.ukwrote in message
news:58**********************************@w39g2000 prb.googlegroups.com...
>I am trying to delete multiple lines in a text file using the
following
Private Sub Read_TextFile()
Dim objReader As StreamReader
Dim strfull, strContents, strContentsold, strContentsnew As
String
objReader = New StreamReader("C:\answer.txt")
'Clear the Text Box1
TextBox1.Clear()
strContentsold = ""
strContentsnew = ""
strContents = ""
strfull = ""
Do While Not objReader.EndOfStream
strContentsold = strContentsnew
strContentsnew = objReader.ReadLine
If strContentsnew = strContentsold Then
strContents = ""
Else
strContents = strContentsnew
End If
strfull += strContents
Loop
TextBox1.Text = strfull
objReader.Close()
End Sub
The text will be stored in TextBox1.
However, it appears not to work! I was wondering if anybody had any
ideas. Here is tan original text file as an example
I assume that you wanted to know whether I can tell you about Wales.
I assume that you wanted to know whether I can tell you about Wales.
whether I can tell you about Wales
Wales is an administrative division in the UK.
Wales
an administrative division
the UK
Source: START KB
Source:
Go back to the START dialog window.
Go back to the START dialog window.
Go back to the START dialog window.