Solved

VBScript UTF-8 file and local character

Posted on 2011-02-23
2
1,628 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 500 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

Suggested Solutions

Title # Comments Views Activity
Create Consolidation Sheet 3 51
Copying directory listing to specific files in another directory 8 43
Calculate age in Microsoft Word 10 69
msiexec won't run 4 25
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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