473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading a Text File

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.
Aug 11 '08 #1
13 1545
However, it appears not to work!

What output did you get?
Aug 11 '08 #2
On Aug 11, 3:22 pm, BobRoyAce <b...@omegasoftwareinc.comwrote:
However, it appears not to work!

What output did you get?
Same as the input!
Aug 11 '08 #3
Hi,

It did work fine for me, however, the code is a little bit very old fashion
(vb6) style. Be aware that everything in Net is an object, while telling
that something is a string is not done anymore.

In the case of appending strings is the stringbuilder more suitable because
that as you append to a string everytime a longer new string is created. (Be
also aware that using the + as a string connecter can give in some cases not
wanted results, use the real connection character & for that, that tells
more direct that it is about string then to prefix everything with str.

I changed your code a little bit.

\\\
Private Sub Read_TextFile()
Dim Reader As IO.StreamReader
Dim ContentsOld, ContentsNew As String
Dim Contents As New System.Text.StringBuilder
Reader = New IO.StreamReader("C:\test\answer.txt")
TextBox1.Clear()
ContentsOld = ""
ContentsNew = ""
Do While Not Reader.EndOfStream
ContentsOld = ContentsNew
ContentsNew = Reader.ReadLine
If ContentsNew <ContentsOld Then
ContentsOld = ContentsNew
Contents.Append(ContentsNew)
End If
Loop
TextBox1.Text = Contents.ToString
Reader.Close()
End Sub
///

Cor

<kr*******@yahoo.co.ukschreef in bericht
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.
Aug 11 '08 #4
On Aug 11, 4:45 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Hi,

It did work fine for me, however, the code is a little bit very old fashion
(vb6) style. Be aware that everything in Net is an object, while telling
that something is a string is not done anymore.

In the case of appending strings is the stringbuilder more suitable because
that as you append to a string everytime a longer new string is created. (Be
also aware that using the + as a string connecter can give in some cases not
wanted results, use the real connection character & for that, that tells
more direct that it is about string then to prefix everything with str.

I changed your code a little bit.

\\\
Private Sub Read_TextFile()
Dim Reader As IO.StreamReader
Dim ContentsOld, ContentsNew As String
Dim Contents As New System.Text.StringBuilder
Reader = New IO.StreamReader("C:\test\answer.txt")
TextBox1.Clear()
ContentsOld = ""
ContentsNew = ""
Do While Not Reader.EndOfStream
ContentsOld = ContentsNew
ContentsNew = Reader.ReadLine
If ContentsNew <ContentsOld Then
ContentsOld = ContentsNew
Contents.Append(ContentsNew)
End If
Loop
TextBox1.Text = Contents.ToString
Reader.Close()
End Sub
///

Cor

<kronec...@yahoo.co.ukschreef in berichtnews:58**********************************@w 39g2000prb.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.
You know that's a great help. What if there were un-ascii characters
in the file for some reason that are not visible?Then two lines
may look similar but differ. How to delete them then!?

K.
Aug 11 '08 #5
If it was my problems then I would do it with this code (a, b, c are not
your fieldnames)

Dim a As String = "1234"
Dim b As New System.Text.StringBuilder
For Each c As Char In a
If AscW(c) 30 AndAlso AscW(c) < 128 Then
b.Append(c)
End If
Next

Where in this case you should evaluate which charactercode you will use
(I have without checking taken 30 and 128)

Don't ask yourself if this is quick enough, this is more then 100000 times
quicker then one pixel move of a textbox on screen.

Cor

<fa*******@yahoo.co.ukschreef in bericht
news:b7**********************************@i24g2000 prf.googlegroups.com...
On Aug 11, 4:45 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
>Hi,

It did work fine for me, however, the code is a little bit very old
fashion
(vb6) style. Be aware that everything in Net is an object, while telling
that something is a string is not done anymore.

In the case of appending strings is the stringbuilder more suitable
because
that as you append to a string everytime a longer new string is created.
(Be
also aware that using the + as a string connecter can give in some cases
not
wanted results, use the real connection character & for that, that tells
more direct that it is about string then to prefix everything with str.

I changed your code a little bit.

\\\
Private Sub Read_TextFile()
Dim Reader As IO.StreamReader
Dim ContentsOld, ContentsNew As String
Dim Contents As New System.Text.StringBuilder
Reader = New IO.StreamReader("C:\test\answer.txt")
TextBox1.Clear()
ContentsOld = ""
ContentsNew = ""
Do While Not Reader.EndOfStream
ContentsOld = ContentsNew
ContentsNew = Reader.ReadLine
If ContentsNew <ContentsOld Then
ContentsOld = ContentsNew
Contents.Append(ContentsNew)
End If
Loop
TextBox1.Text = Contents.ToString
Reader.Close()
End Sub
///

Cor

<kronec...@yahoo.co.ukschreef in
berichtnews:58**********************************@ w39g2000prb.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.

You know that's a great help. What if there were un-ascii characters
in the file for some reason that are not visible?Then two lines
may look similar but differ. How to delete them then!?

K.

Aug 11 '08 #6
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.
Aug 11 '08 #7
On Aug 11, 6:47 pm, "Stephany Young" <noone@localhostwrote:
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.

<kronec...@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.
That's smart Stephany..what are doing for lunch tomorrow?

K.
Aug 11 '08 #8
On Aug 11, 6:47 pm, "Stephany Young" <noone@localhostwrote:
>
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.
I get an error for this last method:

Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

pointing to this line here

If _list(_i - 1).Contains(_list(_i)) Then

I can't see how it can be out of range since you have the index

For _i = 1 To _list.Count - 1

which makes sense.
K.

Aug 11 '08 #9
The test inside the For ... Next loop should read:

If _list(_i - 1).Contains(_List(_i)) Then
_list.RemoveAt(_i)
_removal = True
Exit For
Next

Otherwise the index out of range exception will certainly rear it's ugly
head.
<kr*******@yahoo.co.ukwrote in message
news:39**********************************@t1g2000p ra.googlegroups.com...
On Aug 11, 6:47 pm, "Stephany Young" <noone@localhostwrote:
>>
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.
I get an error for this last method:

Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

pointing to this line here

If _list(_i - 1).Contains(_list(_i)) Then

I can't see how it can be out of range since you have the index

For _i = 1 To _list.Count - 1

which makes sense.
K.
Aug 11 '08 #10
On Aug 11, 8:17 pm, "Stephany Young" <noone@localhostwrote:
The test inside the For ... Next loop should read:

If _list(_i - 1).Contains(_List(_i)) Then
_list.RemoveAt(_i)
_removal = True
Exit For
Next

Otherwise the index out of range exception will certainly rear it's ugly
head.

<kronec...@yahoo.co.ukwrote in message

news:39**********************************@t1g2000p ra.googlegroups.com...
On Aug 11, 6:47 pm, "Stephany Young" <noone@localhostwrote:
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.
I get an error for this last method:
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
pointing to this line here
If _list(_i - 1).Contains(_list(_i)) Then
I can't see how it can be out of range since you have the index
For _i = 1 To _list.Count - 1
which makes sense.
K.
It's working on that example but now I have a harder one!
slightly smaller than Oregon
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
Population:
files like this one above. There can be up to 3 lines repeated.

K.
Aug 11 '08 #11
All I can suggest for that one is for you to study up on Regular
Expressions.
It's working on that example but now I have a harder one!
slightly smaller than Oregon
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
60,776,238 (July 2007 est.)
Population:
Population:
files like this one above. There can be up to 3 lines repeated.

K.
<kr*******@yahoo.co.ukwrote in message
news:72**********************************@u6g2000p rc.googlegroups.com...
On Aug 11, 8:17 pm, "Stephany Young" <noone@localhostwrote:
>The test inside the For ... Next loop should read:

If _list(_i - 1).Contains(_List(_i)) Then
_list.RemoveAt(_i)
_removal = True
Exit For
Next

Otherwise the index out of range exception will certainly rear it's ugly
head.

<kronec...@yahoo.co.ukwrote in message

news:39**********************************@t1g2000 pra.googlegroups.com...
On Aug 11, 6:47 pm, "Stephany Young" <noone@localhostwrote:
>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.
I get an error for this last method:
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
pointing to this line here
If _list(_i - 1).Contains(_list(_i)) Then
I can't see how it can be out of range since you have the index
For _i = 1 To _list.Count - 1
which makes sense.
K.
Aug 11 '08 #12
Hello kr*******@yahoo.co.uk,

Not to nitpick too much, but is it not simpler to prevent the files from
being created in this haphazard fashion in the first place?

--
Rory
Aug 11 '08 #13
On Aug 11, 11:43 pm, Rory Becker <rorybec...@newsgroup.nospamwrote:
Hello kronec...@yahoo.co.uk,

Not to nitpick too much, but is it not simpler to prevent the files from
being created in this haphazard fashion in the first place?

--
Rory
I am looking into this too.

K.
Aug 11 '08 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
0
by: Eric Lilja | last post by:
Hello, I have a text file that contains a number of entries describing a recipe. Each entry consists of a number of strings. Here's an example file with only one entry (recipe): Name=Maple Quill...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.