Solved

Remove two lines of text from inload text file

Posted on 2004-08-11
2
160 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
[X]
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
2 Comments
 
LVL 86

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with opening combobox using VB.NET. 3 37
Iteration Help (Asp.net VB) 5 37
MailAddress in vb 4 36
VB.net -  GroupBox / Panel DataBinding and behavior 3 24
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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