$ZLength()

Returns the length of a sequence of octets measured in bytes, or in "pieces" separated by a delimiter specified by one of its arguments.

The format for the $ZLENGTH() function is:

$ZL[ENGTH](expr1[,expr2])

Examples of $ZLength()

Example:

GTM>write $zlength("主要雨在西班牙停留在平原")
36
GTM>

This uses $ZLENGTH() to WRITE the length in bytes of the sequence of octets "主要雨在西班牙停留在平原".

Example:

GTM>set x=""_$zchar(63)_""_$zchar(63)_""
GTM>write $zlength(x,$zchar(63))
3
GTM>

This uses $ZLENGTH() to WRITE the number of pieces in a sequence of octets, as delimited by the byte code $ZCHAR(63).

Example:

GTM>set x=$zchar(63)_""_$zchar(63)_""_$zchar(63)_""_$zchar(63)"
GTM>write $zlength(x,$zchar(63))
5
GTM>

This also uses $ZLENGTH() to WRITE the number of pieces in a sequence of octets, as delimited by byte code $ZCHAR(63). Notice that GT.M counts both the empty beginning and ending pieces in the string because they are both delimited.