Results 1 to 9 of 9

Thread: [RESOLVED]Deleting a line in a text file that ends with a certain string

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    [RESOLVED]Deleting a line in a text file that ends with a certain string

    Hey,

    I need help deleting a line from a text file. This is for an ASP.net Webpage. I will have a file called Sources.txt. Example data of this file looks like this:

    John|[email protected]
    Bob|[email protected]

    I would like to delete the line ending in |[email protected] programmatically. This will obviously be dynamic. I want to do this by determining what line number it is at, unless of course, there is a better way.

    I want to search for the line by the ending of it so people cannot put [email protected]|[email protected] and accidentally get [email protected] deleted.

    This is for an unsubscribe link.

    Code:
            Dim lines As New List(Of String)(IO.File.ReadAllLines("Sources.txt"))
            lines.RemoveAt(1)
            IO.File.WriteAllLines("Sources.txt", lines.ToArray())
            'Stop people from refreshing and deleting other records.
            Session.Clear()
        End Sub
    Thanks
    Last edited by samtheman; Jul 9th, 2009 at 06:44 PM.
    If you found any of my posts helpful then please rate them.

    CodeBank

    Form Fading Effects in VB.NET and C#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width