?
Solved

VBScript UTF-8 file and local character

Posted on 2011-02-23
2
Medium Priority
?
1,821 Views
Last Modified: 2012-05-11
Hey

I get a UTF-8 file from a employees system ... with the names of the employees.

I’m using fso.opentextfile("myfile.txt")

The local character (Danish) in the names are displayed wrong

If I convert the text file in notepad to ANSI it works.

Who do I convert the file from UTF-8 to ANSI? (or directly when reading the file)

Thanks in advance

Mike

0
Comment
Question by:mikeydk
2 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 34959526
Please see if the last comment in the following works for you:

http://www.issociate.de/board/post/453785/Opening_UTF-8_file_result_in_strange_chars.html
0
 
LVL 7

Accepted Solution

by:
CSI-Windows earned 2000 total points
ID: 35023937

The following code will open a unicode file for reading.  The "-1" in the last position indicates to read in Unicode mode.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTxtStream = oFSO.OpenTextFile(YourFileName, 1,False, -1)

Open in new window


This bit of code is even more flexible, it automatically figures out whether the file is unicode or ansi.

Const ForReading = 1
Const ASCII = 0
Const Unicode = -1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTxtStream 	= oFSO.OpenTextFile(sLogName)
sChar1 = oTxtStream.Read(1)
sChar2 = oTxtStream.Read(1)
oTxtStream.Close
If Asc(sChar1) = 255 And Asc(sChar2) = 254 Then
  'File is UNICODE
  Set oTxtStream = oFSO.OpenTextFile(sLogName, ForReading, False, Unicode)
Else
  'File is ASCII
  Set oTxtStream = oFSO.OpenTextFile(sLogName, ForReading, ReadTheFile, ASCII)
End If

Open in new window


I hope this proposed solution gets you on your way and is sufficient enough to earn some points ;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question