String Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > String commands > !Unicode-Conversion >

String Operations

ATU.

Previous Top Next


MiniRobotLanguage (MRL)

 

ATU.

ANSI to UNICODE String Conversion

 

 

clip1170

 

 

 

Intention

This command converts an ANSI string to its UNICODE equivalent using PowerBASIC's UCODE$ function. The result is placed on the Top of Stack (TOS) or in a specified variable.

The command supports three calling formats: TOS-to-TOS, Variable-to-Variable, and Source-to-Target Variable.

This command is useful for legacy programs that need to handle UNICODE byte strings stored in ANSI format, or when interfacing with APIs that require UNICODE strings in a specific format.

The conversion preserves character data but doubles the byte count (since UNICODE uses 2 bytes per character).

 

Schematic

Input: "Hello" (5 bytes) --> Output: "Hello" (10 bytes, 2 per char)

 |H|e|l|l|o| --> |H|H|e|e|l|l|l|l|o|o|

 ^ (ANSI) ^ (UNICODE via UCODE$)

 

Syntax

ATU.[P1[|P2]]

 

Parameter Explanation

 

No Parameters - Converts TOS to UNICODE and replaces TOS with result.

P1 (Single Parameter) - Converts variable P1 to UNICODE and stores result in P1.

P1|P2 (Two Parameters) - Converts variable P2 to UNICODE and stores result in P1.

 

Examples

 

' TOS conversion: Convert string on stack

$$SRC=Hello

PUSH.$$SRC

ATU.

$$RES=$tos$

' $$RES now contains UNICODE version

 

' Single parameter: Convert and store in same variable

$$TEXT=Test

ATU.$$TEXT

' $$TEXT now contains UNICODE version

 

' Two parameters: Convert source to target variable

$$SRC=ABC

ATU.$$TARGET|$$SRC

' $$TARGET now contains UNICODE version of $$SRC

 

'-------------------------------------------------------------

 

' Conversion Test

'

$$TXT=Hallo

PRT.$$TXT|h

ATU.$$TXT

PRT.$$TXT|h

UTA.$$TXT

PRT.$$TXT|h

MBX.!

ENR.

 

 

 

 

Remarks

 

-Uses PowerBASIC's UCODE$ function for conversion.

-Result is stored as ANSI byte string containing UNICODE data.

-Result string is twice the length of input string (2 bytes per character).

-Variables are resolved once to prevent unwanted expansion.

-No code page parameter supported; uses default system code page.

-For new programs, use WIDE UNICODE variables ($$) instead of this function.

 

Limitations

 

-No explicit code page parameter; uses system default.

-Result is stored as ANSI byte string (not WIDE string).

-Only for legacy conversion; new code should use $$ variables.

 

See also:

VAU. - Variable Unicode

The Stack (TOS)

STR.DELETE

VAR. - Variable Set Value/Clear

LEN. - Length-of-String