Example:
GTM> FOR i=0:1:3 WRITE !,$EXTRACT("HI",i),"<" < H< I< < GTM>
This loop displays the result of $EXTRACT(), specifying no ending character position and a beginning character position "before, " first and second positions, and "after" the string.
Example:
GTM> FOR i=0:1:3 WRITE !,$E("HI",1,i),"<" < H< HI< HI< GTM>
This loop displays the result of $EXTRACT() specifying a beginning character position of 1 and an ending character position "before, " first and second positions, and "after" the string.
Example:
TRIM(x) NEW i,j FOR j=$L(x):-1:0 S nx=$E(x,1,j) Q:$EXTRACT(x,j)'=" " FOR i=1:1:j S fx=$E(nx,i,$L(x)) Q:$EXTRACT(x,i)'=" " QUIT fx GTM>SET str=" MUMPS " GTM>WRITE $LENGTH(str) 7 GTM>WRITE $LENGTH($$TRIM^trim(str)) 5
This extrinsic function uses $EXTRACT() to remove extra leading and trailing spaces from its argument.