I'm loading a Korean CP51949 (EUC-KR) encoded ANSI file into an array of strings (LoadStringsFromFile
). My system and the intended end user systems do not have CP51949 set as a legacy non-Unicode encoding.
At the moment I have 2 problems with this:
- Unless I run the application with Locale Emulator (which is just annoying, since the setup itself is in English only), the Korean text is displayed as gibberish.
Pos
gives wrong results andStringChange
fails completely unless I switch toString
, do the thing, and then back toAnsiString
.
So, I'm wondering if there's a way to convert the array to unicode, and then back before saving.
To convert a file encoded in a specific Ansi encoding to Unicode
string
(UTF-16 LE), useMultiByteToWideChar
function:(Note that I'm using
TStrings
to store strings/lines collection instead ofTArrayOfString
, asTStrings
is easier to work with)To convert Unicode
string
back to Ansi, useWideCharToMultiByte
function:Use the functions like:
Works correctly on my English-only system: