UCODE$ function

Purpose | Translates ANSI bytes into Unicode bytes.
Syntax | a$ = UCODE$(AnsiStrExpression [,CodePage&])

Remarks

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

MyWideString$$ = MyAnsiString$

In this case, the ANSI characters are transparently converted to WIDE UNICODE characters when they are stored in MyWideString$. You should not insert a UCODE$ 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.

UCODE$ presumes that the AnsiStrExpression contains ANSI byte characters stored in an ANSI byte string. It converts them into WIDE UNICODE characters and returns them as an ANSI byte string. To convert a UNICODE byte string into an ANSI byte string, use the ACODE$ 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, UCODE$ returns a string that has double the byte count of the ANSI string, yet represents the same number of characters.

See also | ACODE$, UCODEPAGE