?
Solved

Remove two lines of text from inload text file

Posted on 2004-08-11
2
Medium Priority
?
162 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

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