471,066 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Remove/Delete lines from an array

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
Dec 14 '07 #1
3 5010
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.
"Barkingmadscot" <ba***@bcc-it.co.ukwrote in message
news:19**********************************@d4g2000p rg.googlegroups.com...
>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
Dec 14 '07 #2
>
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
Dec 14 '07 #3
Barkingmadscot wrote:
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.
Dec 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by deko | last post: by
2 posts views Thread by Peter Gomis | last post: by
7 posts views Thread by Srinivasa T.N. | last post: by
12 posts views Thread by Sam Collett | last post: by
reply views Thread by Barkingmadscot | last post: by
reply views Thread by leo001 | last post: by

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.