The format for the $PIECE function is:
$P[IECE](expr1,expr2[,intexpr1[,intexpr2]])
The first expression specifies the string from which $PIECE() computes its result.
A SET command argument can have something that has the format of a $PIECE() on the left-hand side of its equal sign (=). This construct permits easy maintenance of individual pieces within a string. It also can be used to generate a string of delimiters. For more information on SET $PIECE(), refer to “Set”.
$PIECE() can also be used as target in a SET command to change part of the value of a node. Also, when SET arguments have multiple parenthesized (set-left) targets and a target is used as a subscript in more than one item in the list of targets that follow, all the targets use the before-SET value (not the after-SET value) in conformance to the M-standard. For more information on SET $PIECE(), refer to “Set”.
For a proces started in UTF-8 mode, $PIECE() interprets the string arguments as UTF-8 encoded. With VIEW "BADCHAR" enabled, $PIECE() produces a run-time error when it encounters a malformed character, but it does not process the characters that fall after the span specified by the arguments.
$ZPIECE() is the parallel function of $PIECE(). Irrespective of the settings of VIEW "BADCHAR" and $ZCHSET, $ZPIECE() interprets string arguments as a sequence of bytes (rather than a sequence of characters) and can perform all byte-oriented $PIECE() operations. For more information, refer to “$ZPIece()”.
GTM>for i=0:1:3 write !,$piece("1 2"," ",i),"<" < 1< 2< < GTM>
GTM>for i=-1:1:3 write !,$piece("1 2"," ",i,i+1),"<" < 1< 1 2< 2< < GTM>
for p=1:1:$length(x,"/") write ?p-1*10,$piece(x,"/",p)
This example uses $LENGTH() and $PIECE() to display all the pieces of x in columnar format.
GTM>set $piece(x,".",25)="" write x ........................
GTM>set ^x=1,$piece(^a,";",3,2)=^b
This example leaves the naked indicator to pointing to the global ^b.