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 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
Private Sub BTOuvrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTOuvrir.Click
Dim SR As StreamReader = Nothing
Dim SW As StreamWriter = Nothing
Dim fichier As Stream
Dim OFD As New OpenFileDialog
Dim tampon As Char = ""
Dim compteur As Integer = 1
Dim fin As Boolean = False
OFD.InitialDirectory = "c:\"
OFD.FileName = ""
OFD.Filter = "Text files (*.txt)|*.txt"
OFD.FilterIndex = 2
OFD.RestoreDirectory = True
OFD.ShowDialog()
fichier = OFD.OpenFile()
SR = New StreamReader(fichier)
SW = File.CreateText(Replace(OFD.FileName, ".txt", "") + "_codé.txt")
tampon = Convert.ToChar(SR.Read)
While SR.EndOfStream = False
While tampon = Convert.ToChar(SR.Peek())
tampon = Convert.ToChar(SR.Read)
compteur += 1
If SR.Peek = -1 Then
fin = True
Exit While
End If
End While
If compteur > 1 Then
SW.Write(compteur.ToString + tampon)
Else
SW.Write(tampon)
End If
If fin = False Then
tampon = Convert.ToChar(SR.Read)
compteur = 1
End If
End While
If compteur = 1 Then
SW.Write(tampon)
End If
SR.Close()
SW.Close()
End Sub |