11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsThe following example shortens a character string by extracting a from,to range larger thanthe number of values in the replacement string.SET x="ABCDEFGH"SET $EXTRACT(x,3,6)="Z"WRITE xinserts the value “Z” in the third position and removes positions 4, 5 and 6. Variable x nowcontains the value “ABZGH” and has a length of 5.Notes$EXTRACT Compared with $PIECE and $LIST$EXTRACT returns a substring of characters by integer position from a string. $PIECE and$LIST both work on specially formatted strings.$PIECE returns a substring from an ordinary string by using special delimiter characterswithin the string.$LIST returns a sublist of elements from an encoded list by the integer position of elements(not characters). $LIST cannot be used on ordinary strings, and $EXTRACT cannot be usedon encoded lists.$EXTRACT and UnicodeThe $EXTRACT function operates on characters, not bytes. Therefore, Unicode strings arehandled the same as ASCII strings, as shown in the following example using the Unicodecharacter for “pi” ($CHAR(960)):SET a="QT PIE"SET b="QT "_$CHAR(960)SET a1=$EXTRACT(a,-33,4)SET a2=$EXTRACT(a,4,4)SET a3=$EXTRACT(a,4,99)SET b1=$EXTRACT(b,-33,4)SET b2=$EXTRACT(b,4,4)SET b3=$EXTRACT(b,4,99)WRITE !,"ASCII form returns ",!,a1,!,a2,!,a3WRITE !,"Unicode form returns ",!,b1,!,b2,!,b3See Also• SET command• $FIND function• $LENGTH function• $PIECE function208 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!