Solved

VBScript UTF-8 file and local character

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…

740 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