Remove/Delete lines from an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Barkingmadscot

    #1

    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
  • Stephany Young

    #2
    Re: Remove/Delete lines from an array

    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 " <barry@bcc-it.co.ukwrote in message
    news:196b0ff3-aeda-49b9-b495-710afd205321@d4 g2000prg.google groups.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

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Remove/Delete lines from an array

      >
      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


      Comment

      • Phill W.

        #4
        Re: Remove/Delete lines from an array

        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.

        Comment

        Working...