ACODE$ function

Purpose

Translates Unicode bytes into ANSI bytes.

Syntax

a$ = ACODE$(UnicodeStrExpression [,CodePage&])

Remarks

This version of PowerBASIC handles all conversions between ANSI strings and UNICODE strings automatically.  For example:

MyAnsiString$ = MyWideString$$

In this case, the wide characters are transparently converted to byte characters when they are stored in MyAnsiString$.  You should not insert an ACODE$ function here.  The simple fact that the variables are of differing types (ANSI/WIDE) causes the compiler to make all conversions for you, whenever they are needed.

Of course, this automatic conversion was not available in previous versions of the compiler.  In the past, there were no WIDE UNICODE variables offered, so it was necessary to force wide characters into standard byte strings when UNICODE was needed.  The ACODE$ and UCODE$ functions are used for this purpose alone: to support legacy programs which calculated strings in this fashion.

New PowerBASIC programs and updates to your older PowerBASIC programs should use the new WIDE UNICODE variables which are now available.

ACODE$ presumes that the UnicodeStrExpression contains WIDE UNICODE characters stored in an ANSI byte string.  It converts them into ANSI byte characters and returns them as an ANSI string.  To convert an ANSI byte string into a UNICODE byte string, use the UCODE$ function.

If the optional parameter CodePage& is present, it represents the code page to be used for the conversion process.  If not given, the default code page for the locale of the executing computer is used.

Unicode strings require two bytes to represent a Unicode character, whereas ANSI strings (the native PowerBASIC string format) use one byte to represent a character.  Therefore, ACODE$ returns a string that has half of the byte count of the Unicode string, yet represents the same number of characters.

See also

UCODE$, UCODEPAGE