?
Solved

VBScript UTF-8 file and local character

Posted on 2011-02-23
2
Medium Priority
?
1,708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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