Solved remove first line in a text file

Posted on 2009-02-19
Last Modified: 2013-11-26
I have a text file:


john mike      bob       larry
sue     linda    sherry    julie     bobby   mary             cassi

I remove the spaces and replace with commas per code below (Thanks Paul).  I also need to remove the gibbersh on the first line and the 2nd blank line.
Question by:bergertime
    LVL 2

    Author Comment

    I need to amend my question.  I need to remove every line that starts with *****
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    What version VB.Net?

    ...and do you want to:
    (1) Copy the file into memory.  Modify the contents in memory.  Replace the entire original file with the new contents.
    (2) Use a secondary file.  Read original file line by line.  Write the desired lines to the secondary file.  Delete the original file.  Rename the secondary to the original files name.
    LVL 2

    Author Comment

    2005, how bout option 2
    LVL 85

    Accepted Solution

    Haven't tested it yet but something like this should work:
    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim sourceFile As String = "c:\someFile.txt"
            Dim tempFile As String = My.Computer.FileSystem.GetTempFileName
            Dim sr As New StreamReader(sourceFile)
            Dim sw As New StreamWriter(tempFile)
            Dim line As String = sr.ReadLine
            While Not IsNothing(line)
                If Not line.StartsWith("*****") Then
                End If
                line = sr.ReadLine
            End While
            My.Computer.FileSystem.RenameFile(tempFile, sourceFile)
        End Sub
    End Class

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now