ULEN8(

General Form:

ULEN8(strexpr)

The ULEN8( numeric function is used to determine the length in characters of a string expression which is presumed to represent a UTF-8 encoded Unicode string. The result is returned as a numeric value. The ULEN8( function is valid wherever a numeric function is legal.

Trailing spaces are not considered to be part of the string unless it is a literal string or it is enclosed in a STR( expression. If a variable only contains spaces, and no STR( function is used, then the value returned will be 0. This is different to the LEN( function which would have returned 1.

The string must be properly encoded UTF-8 and the result when applied to incorrect encoding is not defined. Remember that HEX(00), HEX(FE) and HEX(FF) characters cannot occur in a UTF-8 string. If you need to validate that a string is properly encoded then use

        $UNPACK(E="UTF-8") sStr$ TO nLen

Examples:

DIM a$16="$€£", b$16 = " "
IF (a$ <> HEX(24E282ACC2A3)) THEN PANIC
IF (ULEN8(a$)) <> 3 THEN PANIC
IF (ULEN8(STR(a$,,8))) <> 5 THEN PANIC
IF (ULEN8(b$)) <> 0 THEN PANIC
IF (ULEN8(STR(b$,,4))) <> 4 THEN PANIC
IF (ULEN8(" ")) <> 1 THEN PANIC
IF (ULEN8(HEX(4120))) <> 2 THEN PANIC