Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read utf-8 text file

Status
Not open for further replies.

SushiLover

Programmer
Oct 29, 2012
5
AU
I have a text file saved as UTF-8 and when I try to read the file it gives me weird characters and not the correct characters (it contains Chinese characters). How can I make it give me the correct Chinese characters?
Code:
Option Explicit
 Dim objFSO, strTextFile, strData, strLine, arrLines, aniTextFile, aniData, aniLines, aniLine, objTextFile, fso, inputFileList, listFile, fname
 Dim iim1, iret, iret2, iret3, i
 Const ForReading   = 1
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 strTextFile = "C:\Users\admin\Desktop\ArtistCG\folder.txt"
 strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
 arrLines = Split(strData,vbCrLf)
 aniTextFile = "C:\Users\admin\Desktop\ArtistCG\folder-list.txt"
 aniData = objFSO.OpenTextFile(aniTextFile,ForReading).ReadAll
 aniLines = Split(aniData,vbCrLf)
 For i = 0 To UBound(arrLines)
   strData = objFSO.OpenTextFile(arrLines(i),ForReading).ReadAll
   WScript.Echo strData
   Set listFile = objFSO.OpenTextFile(aniLines(i),ForReading)
   Do While Not listFile.AtEndOfStream
     fName = listFile.ReadLine
     WScript.Echo fName
   Loop
   listFile.Close
 Next
 
Try to use unicode:
Set listFile = objFSO.OpenTextFile(aniLines(i),ForReading[!],,-1[/!])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you need to read UTF-8, check out the ADODB.Stream.
Here's some code that should get you started:

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top