472,980 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 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 5443
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: deko | last post by:
I'm not sure how to do this in php - need to calculate and delete an unspecified number of lines from the *top* of a file. <?php //append $visitor to the bottom of $visdata $fp =...
2
by: Peter Gomis | last post by:
I have encountered a situation where I am unable to remove a .NET assembly from the GAC. The message I receive is "Assembly 'assemblyname' could not be uninstalled because it is required by other...
7
by: Srinivasa T.N. | last post by:
Hi, I want to delete the first 3 lines and last 3 lines of a file. How can I do it? I want to repeat on multiple files.. TIA Regards, Seenu.
1
by: YT | last post by:
Howdy, Why the heck wouldn't this work: for each item in Session.Contents if NOT( Instr( item, "customer_" ) = 1 OR Instr( item, "user_" ) = 1 ) Then Session.Contents( item ) = ""...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
19
by: brasilino | last post by:
Hi Folks: I've been looking (aka googling) around with no success. I need a usability beyond 'pop()' method when removing an Array elements. For example: oName = new...
0
by: Barkingmadscot | last post by:
I am stuck, i cant work out how to remove lines from an array I am loading a text file (a Log) into an array, I know which lines a need, but the logs can be upto 30K sometimes bigger. I found...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.