By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Remove/Delete lines from an array

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
>
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

P: n/a
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.