Remove two lines of text from inload text file

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


Question by:BOOBIC
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

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

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

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

Author Comment

ID: 11777525
Let me play with that.


Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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