Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1441 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [Résolu] Ecrire un fichier au format UTF-8

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Résolu] Ecrire un fichier au format UTF-8

n°1333359
didier1809
${citation_perso}
Posté le 28-03-2006 à 10:46:42  profilanswer
 

:hello:  
 
Je cherche à écrire des fichiers au format utf-8, mais avec la méthode  

Code :
  1. object.OpenTextFile (filename [, iomode[, create[, format]]])


Le format n'est 'que' Unicode ou ASCII ...
 
Avez vous une solution ?
 
Merci d'avance


Message édité par didier1809 le 30-03-2006 à 10:45:40

---------------
.
mood
Publicité
Posté le 28-03-2006 à 10:46:42  profilanswer
 

n°1333524
didier1809
${citation_perso}
Posté le 28-03-2006 à 12:38:57  profilanswer
 

:sweat:


---------------
.
n°1333656
didier1809
${citation_perso}
Posté le 28-03-2006 à 14:10:26  profilanswer
 

Apparement, ca n'a pas l'air bien répendu ce type de question :(


---------------
.
n°1334341
didier1809
${citation_perso}
Posté le 29-03-2006 à 08:46:41  profilanswer
 

:hello:


---------------
.
n°1334622
didier1809
${citation_perso}
Posté le 29-03-2006 à 15:04:33  profilanswer
 

Pas de solution ?
 
(Je ne veux pas ouvrir chaque fichier avec notepad++ pour l'encoder en UTF-8, j'ai plus de 10.000 fichiers à écrire  [:psywalk] )


---------------
.
n°1335338
didier1809
${citation_perso}
Posté le 30-03-2006 à 10:45:17  profilanswer
 

J'ai trouvé la solution :
 
1. The old visual basic file commands shouldn't be used. If I remember correctly, Microsoft didn't even provide documentation for those command in VB6. They want you to use FSO or ADODB
 
2. Unicode is a collection of character sets (e.g. UTF-16, UTF-8). Each encoding will produce a different file (i.e. size and contents)
 
3. StrConv(strText, vbUnicode) produces UTF-16 (the default Windows Unicode format) not UTF-8
 
4. Set objTextStream = objFSO.CreateTextFile(strFile, , True) outputs as UTF-16 not UTF-8
 
There's only one way to do what your asking. Use a stream.
 
For example ...
 

Code :
  1. Private Sub CreateFile(ByVal pstrFile As String, ByVal pstrData As String)
  2.   Dim objStream As Object
  3.  
  4.   'Create the stream
  5.   Set objStream = CreateObject("ADODB.Stream" )
  6.   'Initialize the stream
  7.   objStream.Open
  8.   'Reset the position and indicate the charactor encoding
  9.   objStream.Position = 0
  10.   objStream.Charset = "UTF-8"
  11.  
  12.   'Write to the steam
  13.   objStream.WriteText pstrData
  14.  
  15.   'Save the stream to a file
  16.   objStream.SaveToFile pstrFile
  17.  
  18. End Sub


---------------
.

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [Résolu] Ecrire un fichier au format UTF-8

 

Sujets relatifs
[Résolu] [Batch] [Newbies] Diverses questions au sujet du Batch[VBA] [Résolu] Liste de choix
[Résolu] Créer un objet à partir du nom de son type[résolu] Problème bouton / javascript
Problème de ponctuation ds un fichier texte dynamique ds flash[résolu] !! interprétation IE / Firefox !!
[Résolu] code instable[résolu] Frames vs css ? mise a jour de mon site...
recuperer chemin fichier[resolu]Problème d'alignement
Plus de sujets relatifs à : [Résolu] Ecrire un fichier au format UTF-8


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR