1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, Fich1, Fich2, Ret, TBLigneLue, Ind, K, SousChaine, Recherche
Set fso = CreateObject("Scripting.FileSystemObject")
Set fich1 = fso.OpenTextFile("Ventes.txt", ForReading, False) ' Adapter le chemin
Set fich2 = fso.OpenTextFile("VentesAfter.txt", ForAppending, True) ' Nouveau fichier pour ne pas toucher à l'original
Ret = fich1.ReadALL
fich1.Close
TBLigneLue = Split(Ret, vbNewLine, -1, vbTextCompare)
For K = 0 To Ubound(TBLigneLue)
Ret = TBLigneLue(K)
Ind = 0
Recherche = ""
Do
Ind = Ind + 1
SousChaine = SousChaine & Mid(Ret, Ind, 1)
If Asc(Mid(Ret, Ind, 1)) >= 48 And Asc(Mid(Ret, Ind, 1)) <= 57 Then
Recherche = Recherche & Mid(Ret, Ind, 1)
End If
Loop Until Ind >= Len(Ret)
' MsgBox Recherche ' Juste pour le test
SousChaine = Replace(SousChaine, Recherche, Right("00" & Recherche, 3))
Fich2.Write SousChaine & vbNewLine
Recherche = "" : SousChaine = ""
Next
Fich2.Close
' Nettoyage
Set fich1 = Nothing
Set fich2 = Nothing
Set fso = Nothing |
Partager