Conversion d'un fichier texte ANSI en UNICODE
Bonjour,
J'essai de convertir un fichier texte ANSI en UNICODE:
J'ai donc essayé ce code mais sans succés, le fichier restant toujours codé ANSI.
Code:
1 2 3 4 5 6 7
| Public Shared Sub EncodeInUnicode(ByVal Path As String, ByVal Text As String)
' read with the **local** system default ANSI page
Text = File.ReadAllText(Path, Encoding.Default)
' write as Unicode (if you want to do this)
File.WriteAllText(Path, Text, Encoding.Unicode)
End Sub |
et j'utilise la fonction ainsi:
Code:
EncodeInUnicode("c:\temp", "RRGoogleMapsTools.txt")
J'ai aussi testé les 2 codes suivants:
Code:
1 2 3 4 5 6 7 8 9 10
| Public Shared Sub EncodeInUnicode(ByVal WFic As String)
' 1 : Lire et écrire le fichier texte en spécifiant le codage
'Dim MonFichier As String = IO.File.ReadAllText(WFic, System.Text.Encoding.ASCII)
'IO.File.WriteAllText(WFic, MonFichier, System.Text.Encoding.Unicode)
' 2 : Lire le contenu du fichier (en bytes), faire la conversion, réécrire les données dans le fichier
Dim Bytes() As Byte = IO.File.ReadAllBytes(WFic)
System.Text.Encoding.Convert(System.Text.Encoding.ASCII, System.Text.Encoding.Unicode, Bytes)
IO.File.WriteAllBytes(WFic, Bytes)
End Sub |
Merci de votre aide:lol: