How Do I Convert Between ANSI and Unicode? (Magic xpa 2.x)
When you are converting between Ansi and Unicode, it is important to remember that there are different ANSI code pages. While only the numeric codes between 0 and 255 (0 to FF, in hex) are used, each character displays differently depending on the code page used to interpret it. Different code pages are used depending on the language currently being supported, or, prior to the Windows era, the kind of graphic support needed.
For instance, suppose we generate the character codes from 34 to 255, and display them using the old code page 437, which uses the graphic characters:
If we display those same characters using the Windows XP default code page we get:
So, Unicode has a character conversion for all these characters, but it needs to know that the number 251 is a checkmark or an umlaut u. We do this by specifying the code page when doing the conversion.
The function in Magic xpa to convert strings from ANSI to Unicode is:
UnicodeFromANSI (String, CodePage)
So, if M is our string with all the Ascii codes, and we use UnicodeFromANSI (M, 0), we get:
But if we use UnicodeFromANSI (M, 437) we get:
You can convert from Unicode back you ANSI by using the function:
UnicodeToANSI (String, CodePage)
The Online and Rich Client Samples projects (program UN03 and RUN03)