View Single Post
 
Old 06-22-2017, 04:29 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

Hi,

You could try this. Needs a reference to Microsoft Scripting Runtime.

Code:
Private Sub Command1_Click()
Dim fso As Scripting.FileSystemObject
Dim ts As TextStream
Dim sPath As String
Dim sTxt As String

sPath = <your text file path>
'open text file and read text to variable
Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile(sPath, ForReading)
sTxt = ts.ReadAll
ts.Close
'replace ## with #
Do While InStr(sTxt, "##") > 0
    sTxt = Replace(sTxt, "##", "#")
Loop
'write text back to text file
Set ts = fso.OpenTextFile(sPath, ForWriting)
ts.Write sTxt
ts.Close
Set fso = Nothing
Set ts = Nothing
End Sub
Or if you don't want to use the file system object

Code:
Private Sub Command1_Click()
Dim sPath As String
Dim ffile As Integer
Dim sTxt As String

sPath = <your text file path>
'open text file and read text to variable
ffile = FreeFile
Open sPath For Input As #ffile
sTxt = input(LOF(ffile), ffile)
Close #ffile
'replace ## with #
Do While InStr(sTxt, "##") > 0
    sTxt = Replace(sTxt, "##", "#")
Loop
'write text back to text file
Open sPath For Output As #ffile
Print #ffile, sTxt
Close #ffile
End Sub

Last edited by Daigon Ali; 06-22-2017 at 06:36 AM.
Reply With Quote