Remove/Delete lines from an array

B

Barkingmadscot

I am stuck, i can workout how to remove lines from an array

I have loading a text file (a Log), I know which lines a need, but
the logs can be upto 30K sometimes bigger. I found trying to delete
the lines from the log file before loading in the array took ages, i
thought i would be alot quicker to put in an array and remove the
unwanted lines.

Dim text As Array
Dim lines As New List(Of String)
text = File.ReadAllLines(strLogDestPath & fileNm)
lines.AddRange(text)

lines.RemoveAt(1) - I thought this should have removed the
array index 1

When i took at the before and after this line nothing has changed??

Any help would be greate ta
 
S

Stephany Young

Forget about your array!

You are dealing with a List(Of String)

Try loading it thus:

Dim lines As New List(Of String)(File.ReadAllLines(strLogDestPath &
fileNm))

then

lines.RemoveAt(1)


but!!!!!!!!! remember that such list (as are arrays) are 0 based, therefore
element 1 is the 2nd element in the list, NOT the first.

To remove the first element use:

lines.RemoveAt(0)

If you know how many elements you need to remove you can use:

lines.RemoveRange(0, n)

where n is the number of elements to remove.
 
C

Cor Ligthert [MVP]

but!!!!!!!!! remember that such list (as are arrays) are 0 based,
therefore element 1 is the 2nd element in the list, NOT the first.
What was in my idea the problem of the OP. However nicely done Stephany.

I have read about New Zealand yesterday, all woman on top.

:)

Cor
 
P

Phill W.

Barkingmadscot said:
I have loading a text file (a Log), I know which lines a need, but
the logs can be upto 30K sometimes bigger.

30KB is /not/ big for a log file!
I found trying to delete the lines from the log file before loading
in the array took ages, i thought i would be a lot quicker to put in
an array and remove the unwanted lines.

I think you'd be better off loading the file in but then finding and
processing just the lines you're interested in (and ignore the rest).


HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top