Solved

VBScript UTF-8 file and local character

Posted on 2011-02-23
2
1,520 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
Comment Utility
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 500 total points
Comment Utility

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now