|
-
Jul 9th, 2009, 04:09 PM
#1
Thread Starter
Hyperactive Member
[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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|