Comment écrire dans un fichier en Unicode dans Vb.Net
-
26-09-2019 - |
Question
Comment dois-je modifier le code Vb.Net suivant pour écrire str
au fichier en unicode?
Dois-je besoin de convertir str
Unicode avant d'écrire dans le fichier?
Using sw As StreamWriter = New StreamWriter(fname)
sw.Write(str)
sw.Close()
End Using
La solution
Utilisez le constructeur surchargée pour spécifier le codage
Using sw As StreamWriter = New StreamWriter(fname, true, System.Text.Encoding.Unicode)
sw.Write(str)
sw.Close()
End Using
Choisissez UTF8 (8bit) ou Unicode jeu de caractères (16 bits) de codage selon vos besoins.
Autres conseils
Documentation dit que StreamWriter
utilisations UTF8-Encoding par défaut.
Le Code ci-dessous indique explicitement enregistrer en tant que UTF-8 sans BOM.
Dim utf8WithoutBom As New System.Text.UTF8Encoding(False)
Dim orfWriter As System.IO.StreamWriter = New System.IO.StreamWriter(fileName, append, utf8WithoutBom)
orfWriter.Write(saveString)
orfWriter.Close()
Pour la documentation complète, consultez www.ezVB.net .
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow