Skip to content

$ZExtract()

$ZExtract()

Returns a byte sequence from a given sequence of octets (8-bit bytes).

The format for the $ZEXTRACT function is:

$ZE[XTRACT](expr[,intexpr1[,intexpr2]])
  • The expression specifies a sequence of octets (8-bit bytes) from which $ZEXTRACT() derives a byte sequence.
  • The first optional integer expression (second argument) specifies the starting byte position in the byte string. If the starting position is beyond the end of the expression, $ZEXTRACT() returns an empty string. If the starting position is zero (0) or negative, $ZEXTRACT() starts at the first byte position in the expression; if this argument is omitted, $ZEXTRACT() returns the first byte. $ZEXTRACT() numbers byte positions starting at one (1) (the first byte of a sequence of octets (8-bit bytes) is at position one (1)).
  • The second optional integer expression (third argument) specifies the ending byte position for the result. If the ending position is beyond the end of the expression, $ZEXTRACT() stops with the last byte of the expression. If the ending position precedes the starting position, $ZEXTRACT() returns null. If this argument is omitted, $ZEXTRACT() returns one byte.
  • $ZEXTRACT() provides a tool for manipulating strings based on byte positions.
  • As $ZEXTRACT() operates on bytes, it can produce a string that is not well-formed according to the UTF-8 character set.

Examples of $ZEXTRACT()

Example:

GTM>Set A="主要雨在西班牙停留在平原" 
        
GTM>For i=0:1:$zlength(A) 
GTM>write !,$zascii($zextract(A,i)),"|"
GTM>

This example displays the numeric byte sequence of the sequence of octets (“主要雨在西班牙停留在平原”).