|
-
Jul 5th, 2010, 09:04 AM
#3
Re: [VB6] BigTextBox - Log Large Amounts of Text to a TextBox
Ahh, they are in the file but you won't see them using Notepad. Notepad is Unicode-aware and handles things like a UTF-8 BOM. Those first 3 characters would be the BOM. A BOM is metadata, not characters.
It looks very much as if you are trying to treat a UTF-8 file as an ANSI (not ASCII) file.
Classic VB (4, 5, 6) native I/O statements treat text files as ANSI on disk encoded using the current system codepage, and translate this data to UTF-16LE (what Windows calls "Unicode") on read and from Unicode on write.
Windows systems really should never have UTF-8 files on them. However people have "bent over" for the open source crowd who mainly tout Unix/Linux standards. It doesn't help that so many kowtow to the PHP mentaility either - which has a Unix/Linux dominated philosophy. Those systems have very poor Unicode support natively, and often fall back on UTF-8 because much of the time ASCII text can be claimed to be UTF-8.
ANSI characters sets on Windows look a lot like ASCII with the addition of character codes from 128 to 255. UTF-8 looks the same as ASCII as long as you never use characters above 127.
To properly read a UTF-8 file in VB6 you have three basic choices:
- Use the ADO.Stream object, which can be used to read and write files of many encodings including most Unicode variations such as UTF-8.
- Use VB6 binary I/O and do a proper manual translation of the encoded text.
- Read it as text, strip off the BOM bytes (whch will look like 3 strange characters in a VB String), and hope for the best (no characters above 127).
Note that in UTF-8 encoding characters between 0 and 127 will be represented by one byte. Characters in other ranges each take up two or more bytes in the file. UTF-8 is a variable character length encoding.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|