473,656 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ReadAllLin es(strLogDestPa th & 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 5586
Forget about your array!

You are dealing with a List(Of String)

Try loading it thus:

Dim lines As New List(Of String)(File.Re adAllLines(strL ogDestPath &
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.RemoveRan ge(0, n)

where n is the number of elements to remove.
"Barkingmadscot " <ba***@bcc-it.co.ukwrote in message
news:19******** *************** ***********@d4g 2000prg.googleg roups.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.ReadAllLin es(strLogDestPa th & 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
2655
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 = fopen($visdata,"a"); fwrite($fp, "\n".$visitor;) //count the lines in $visdata $lines = count($visdata); if $lines > 10
2
20644
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 applications." Although I have seen this before when trying to remove .NET assemblies that have been installed via an MSI package, I now get this message while trying to remove any assembly I've added to the GAC. Using gacutil does not work...
7
13348
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
3085
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 ) = "" Session.Contents.Remove( item ) end if next 'item
12
55547
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 also removed) So far I have (val is value, ar is array, returns new array):
3
5399
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 example first:
19
6314
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 Array('Lucas','Brasilino','Silva'); oName.remove('Brasilino'); oName.toString(); // puts out 'Lucas,Silva'
0
344
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 trying to delete the lines from the log file before loading in the array took ages, i thought it would be alot quicker to put it in an array and remove the unwanted lines. Also the files it stored on a network drive so i think the array option is...
6
4247
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 this program has more then one class and also uses an interface. Right now I am working on ArrayBasedPD class. I am trying to write a code for the remove method (line 158) that allows the user to enter a name, once the program sees that the name is...
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.