Salesforce

How Do I Convert Between ANSI and Unicode? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Convert Between ANSI and Unicode? (Magic xpa 3.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)

where:

  • String is the ANSI alpha string to convert

  • CodePage is the code page that will be used to interpret the ANSI.

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:

Converting from Unicode back to ANSI

You can convert from Unicode back you ANSI by using the function:

UnicodeToANSI (String, CodePage)

where:

  • String is the Unicode alpha string to convert

  • CodePage is the code page that will be used to interpret the ANSI.

See also

The Online and Rich Client Samples projects (program UN03 and RUN03)

Reference
Attachment 
Attachment