Also, see if this helps.
Public Class Form1
Private myFile As String = "C:\test.txt" '// your File to Load/Edit if needed/Save.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myFile) Then '// check if File Exists.
Dim arTemp() As String = IO.File.ReadAllLines(myFile) '// Load File Lines in a String Array.
Dim sTemp As String = Nothing '// String used to keep only selected File lines.
Dim bKeepFileLines As String = True '// determine if worth keeping the remaining File Lines or Not.
For Each fileLine As String In arTemp '// Loop thru all File Lines in the String Array.
If fileLine.StartsWith("****") Then bKeepFileLines = False '// check if line.StartsWith... and set to False NOT to keep the File Lines.
If fileLine.StartsWith(";") Then bKeepFileLines = True '// once Locating the ";", it sets to Keep the remaining File Lines.
If bKeepFileLines = True Then '// if set to True, keep the File Lines.
If Not sTemp = Nothing Then '// check if Not Empty, add a Line Break and the Line Content.
sTemp &= vbNewLine & fileLine
Else '// add only the Line Content.
sTemp = fileLine
End If
End If
Next
IO.File.WriteAllText(myFile, sTemp) '// Save File back: IO.File.WriteAllText(File Name, File Content to Save)
MsgBox("File Edited and Saved.", MsgBoxStyle.Information) '// Display confirmation that File has been modified and Saved.
Else
MsgBox("File Does Not Exist.", MsgBoxStyle.Critical) '// Display confirmation if File Does Not Exist.
End If
End Sub
End Class
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384