Examples of $PIECE()

Example:

    GTM> FOR i=0:1:3 WRITE !,$PIECE("1 2"," ",i),"<"
    <
    1<
    2<
    <
    GTM>
    

This loop displays the result of $PIECE(), specifying a space as a delimiter, a piece position "before," first and second, and "after" the string.

Example:

    GTM> FOR i=-1:1:3 WRITE !,$PIECE("1 2"," ",i,i+1),"<"
    <
    1<
    1 2<
    2<
    <
    GTM>
    

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

Example:

    F p=1:1:$L(x,"/") W ?p-1*10,$piece(x,"/",p)
    

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

Example:

    GTM> s $P(x,".",25)="" W x
    ........................
    

This SETs the 25th piece of the variable x to null, with a delimiter of a period. This produces a string of 24 periods preceding the null.