Edit a text file

  • Thread starter Thread starter m
  • Start date Start date
M

m

I need to bring in a text file to a variable and then run
the replace() function against it and then put it back out
to a text file.

Can anyone provide a code sample for doing this?

thanks in advance
 
Hi,
Here are two functions that will help:

Public Function FileIntoString(PathToFile As String) As String
Dim strFile As String
Dim strTemp As String
strFile = String(FileLen(PathToFile), " ")
Open PathToFile For Input As #1
Do While Not EOF(1)
Line Input #1, strTemp
strFile = strFile & strTemp
Loop
Close #1
FileIntoString = strFile

End Function

modify your string and write to the file:

Public Sub WriteToFile(strIn As String, PathToFile As String)
Dim strOut As String
strOut = "test"
Open PathToFile For Output As #1
Print #1, strIn
Close #1
End Sub
 
Back
Top