Sub test_txt()
Dim FSO As New FileSystemObject
Dim tsT As TextStream
Dim s As String
s = FSO.BuildPath(Environ("userprofile"), "Documenti")
s = FSO.BuildPath(s, "prova.txt")
Set tsT = FSO.OpenTextFile(s, ForWriting, True)
With tsT
.Write "123 roberto mensa"
.WriteBlankLines (1)
.Write "0 enzo pellegrino"
.WriteBlankLines (1)
.Write "1 enzo pellegrino"
.WriteBlankLines (1)
.Write "0 enzo pellegrino"
.WriteBlankLines (1)
.Write "1 enzo pellegrino"
.Close
End With
Replace_in_txt s, "0", "xxx"
End Sub
Sub Replace_in_txt(sPath As String, _
sTrova As String, sRip As String)
Dim FSO As New FileSystemObject
Dim tsT As TextStream
Dim s As String
Dim RE As New RegExp
Set tsT = FSO.OpenTextFile(sPath, ForReading, True)
With tsT
s = tsT.ReadAll
End With
tsT.Close
Set tsT = FSO.OpenTextFile(sPath, ForWriting, True)
RE.Global = True
RE.Pattern = "
0"
If RE.Test(s) Then
s = RE.Replace(s, Chr(10) & sRip)
End If
tsT.Write s
tsT.Close
End Sub
|