Iczer

Encoding after FileOpen/FileRead

5 posts in this topic

#1 ·  Posted

If I FileOpen/FileRead some UTF-8 file, then as result, what encoding of text I get? UTF-8 or UTF-16LE?

$hFile = FileOpen($sFilePath,$FO_UTF8)
$sFile = FileRead($hFile)
         FileClose($hFile)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You will get the UTF-8 interpretation of the binary. I am no expert on this, but you may sometimes get the same characters when you open a file in the wrong encoding, depending on byte-order and possibly a number of other factors. I'm hoping someone with more working knowledge can correct me if I'm wrong, or add further information.

Edited by czardas

Share this post


Link to post
Share on other sites

#3 ·  Posted

At first i'm also thought it would be UTF-8 but... I have RSS XML File - it UTF-8 encoded. If I open and read it with $FO_UTF8, and then parse it (without errors) and display result in "_ArrayDisplay()" function I'm getting normal text, even if it Unicode. But if i Try to use

$sXML = _WinAPI_MultiByteToWideChar($sXML, 65001, 0, True)
$sXML = StringReplace($sXML,'encoding="utf-8"','encoding="utf-16"')

After "FileRead()" I'm get parse errors and any Unicode text replaced by question marks "???"...

Share this post


Link to post
Share on other sites

#4 ·  Posted

@Iczer,

Since the file is open in UTF8 mode, FileRead will interpret UTF8 content and yield a native (UTF16) string. Zero need for user-side conversion.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now