$ZPiece()

Return a sequence of bytes delimited by a specified byte sequence made up of one or more bytes.

The format for the $ZPIECE function is:

$ZP[IECE](expr1,expr2[,intexpr1[,intexpr2]])

Examples of $ZPIECE()

Example:

GTM>for i=0:1:3 write !,$zpiece(""_$zchar(64)_"",$zchar(64),i),"|"

|
|
|
|
GTM>

This loop displays the result of $ZPIECE(), specifying $ZCHAR(64) as a delimiter, a piece position "before," first and second, and "after" the sequence of octets.

Example:

GTM>for i=-1:1:3 write !,$zpiece(""_$zchar(64)_"",$zchar(64),i,i+1),"|"

|
|
@|
|
|

GTM>

This example is similar to the previous example except that it displays two pieces on each iteration. Notice the delimiter () in the middle of the output for the third iteration, which displays both pieces.

Example:

For p=1:1:$ZLength(x,"/") Write ?p-1*10,$ZPiece(x,"/",p)

This loop uses $ZLENGTH() and $ZPIECE() to display all the pieces of x in columnar format.

Example:

GTM>Set $piece(x,$zchar(64),25)="" write x
新年好@@@@@@@@@@@@@@@@@@@@@@@@

This SETs the 25th piece of the variable x to null, with delimiter $ZCHAR(64). This produces a byte sequence of 24 at-signs (@) preceding the null.