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 34 35 36 37 38 39 40
|
Imports System
Imports System.IO
Module Module1
Public chemin, ficOrigine, ficDestination, Mot As String
Public Car As Byte
Public Sub Main()
Dim i, longueur As Integer
chemin = CurDir() 'Application.StartupPath
ficOrigine = chemin & "\Quelques mots.txt"
ficDestination = chemin & "\Résultat.txt"
longueur = FileLen(ficOrigine)
FileOpen(1, ficOrigine, OpenMode.Binary, OpenAccess.Read)
FileOpen(2, ficDestination, OpenMode.Binary, OpenAccess.Write)
'Lit tous les Bytes du fichier original
Try
For i = 1 To longueur
FileGet(1, Car) 'Lecture du 1er Byte et des suivants
If Car <> 32 Then 'Si différent d'un espace
If Car = 44 Then 'Si c'est une virgule
Car = 13
FilePut(2, Car) 'Ecrit un saut de ligne
Car = 10
FilePut(2, Car) 'Ecrit un retour chariot
Else
FilePut(2, Car) 'Sinon, écrit le Byte lu précédemment
End If
End If
Next
Catch ex As Exception
MsgBox(ex.Message) 'Affiche l'erreur, s'il y en a une
End Try
FileClose(1)
FileClose(2)
End Sub
End Module |
Partager