Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Read and Write Unicode


  • Please log in to reply
1 reply to this topic
PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
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).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Nice functions. Thanks for packaging them up so nicely, and with a demonstration.