11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsSET sentence="The quick brown fox jumped over the lazy dog's back."SET delim=" "SET countdown=$LENGTH(sentence,delim)SET countup=1FOR reps=countdown:-1:1 {SET extract=$PIECE(sentence,delim,countup)WRITE !,countup," ",extractSET countup=countup+1}WRITE !,"All done!"$PIECE and $LISTThe data storage methods used by $PIECE and the $LIST functions are incompatible andshould not be combined. For example, attempted to use $PIECE on a list created using$LISTBUILD yields unpredictable results and should be avoided.The $LIST functions specify substrings without using a designated delimiter. If setting asidea delimiter character or character sequence is not appropriate to the type of data (for example,bitstring data), you should use the $LISTBUILD and $LIST functions to store and retrievesubstrings.Null Values$PIECE does not distinguish between a delimited substring with a null string value, and anon-existent substring. Both return a null string value. For example, the following examplesboth return the null string for a from value of 7:SET colorlist="Red,Green,Blue,Yellow,Orange,Black"SET extract1=$PIECE(colorlist,",",6)SET extract2=$PIECE(colorlist,",",7)WRITE "6=",extract1,!,"7=",extract2SET colorlist="Red,Green,Blue,Yellow,Orange,Black,"SET extract1=$PIECE(colorlist,",",6)SET extract2=$PIECE(colorlist,",",7)WRITE "6=",extract1,!,"7=",extract2In the first case, there is no seventh substring; a null string is returned. In the second casethere is a seventh substring, as indicted by the delimiter at the end of the plist string; the valueof this seventh substring is the null string.The following example shows null values within a plist. It extracts substrings 1 and 3. Thesesubstrings exists, but both contain a null string. (Substring 1 is defined as the string precedingthe first delimiter character):SET colorlist=",Red,,Blue,"SET extract1=$PIECE(colorlist,",")SET extract3=$PIECE(colorlist,",",3)WRITE !,"sub1=",extract1,!,"sub3=",extract3284 <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!