Jump to content


Photo

Read and Write Unicode


  • Please log in to reply
1 reply to this topic

#1 PhiLho

PhiLho
  • Fellows
  • 6850 posts

Posted 18 July 2006 - 04:28 PM

Two persons had some trouble with Unicode: FileAppend Unicode text and Reading € from a file.
These were opportunities to develop some code around Microsoft's MultiByteToWideChar and WideCharToMultiByte functions.
As BoBo suggested, this code seems mature enough to put in this section.
The script I give here has no practical use as is. It is merely a demonstration of use of the functions, and is mostly designed as code snippets to copy and paste where needed.

It shows:
- Convert a text from plain Windows Ansi (ISO-8859-1/CP-1252) to Windows' Unicode (UCS-2/UTF-16) and back.
- Write and re-read a text encoded in Win Unicode, with or without Bom.
- Convert UTF-8 to Ansi (if relevant).
- Convert UTF-8 string to Win Unicode (UTF-16) and display it in a GUI (example with Japanese string).

The script must be downloaded: ReadWriteUnicodeText.ahk (it is 200 lines long, I don't like long code sections, and you can find fragments in the above topics).

#2 Chris

Chris
  • Administrators
  • 10727 posts

Posted 23 July 2006 - 02:15 AM

Nice functions. Thanks for packaging them up so nicely, and with a demonstration.