Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
Dim txt As String = My.Computer.FileSystem.ReadAllText(ofd.FileName)
Debug.Print("Original Text:")
Debug.Print("--------------------------------------------------")
Debug.Print(txt)
Debug.Print("")
Dim pattern As String = "(.+)\1{5,}"
txt = System.Text.RegularExpressions.Regex.Replace(txt, pattern, "")
Debug.Print("Modified Text:")
Debug.Print("--------------------------------------------------")
Debug.Print(txt)
' Uncomment the line below when you are sure the RegEx is working as desired!
' My.Computer.FileSystem.WriteAllText(ofd.FileName, txt, False)
Catch ex As Exception
MessageBox.Show("File: " & ofd.FileName & vbCrLf & vbCrLf & ex.ToString, "Error Modifying File", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Using
End Sub
End Class
|