Solved

Remove two lines of text from inload text file

Posted on 2004-08-11
2
158 Views
Last Modified: 2010-04-23
Hi everyone:

How to remove first two lines from text file before statring proccessing data from that file. Usually those two lines represent the date file was written(first line) and receiver name (second line). Later data dumped to SQL.

RGDS
Sam

0
Comment
Question by:BOOBIC
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 11777442
This will remove the first two lines from a file:

    Private Sub removeFirstTwoLines(ByVal inputFile As String)
        Dim fileLines As ArrayList = New ArrayList
        Dim count As Integer = 0

        If System.IO.File.Exists(inputFile) Then
            Dim sr As System.IO.StreamReader = New System.IO.StreamReader(inputFile)
            Dim line As String

            Do
                line = sr.ReadLine()
                If Not (line Is Nothing) Then
                    count = count + 1
                    If count > 2 Then
                        fileLines.Add(line)
                    End If
                End If
            Loop While Not (line Is Nothing)
            sr.Close()

            Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(inputFile)
            For Each line In fileLines
                sw.WriteLine(line)
            Next
            sw.Close()
        Else
            MsgBox("Unable to locate " & inputFile, MsgBoxStyle.Critical, "File Not Found")
        End If
    End Sub
0
 

Author Comment

by:BOOBIC
ID: 11777525
Let me play with that.

RGDS
Sam
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question