Solved

Remove two lines of text from inload text file

Posted on 2004-08-11
2
157 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now