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.

In the following example, both $PIECE functions returns the entire plist string, because thereare no occurrences of delimiter in the plist string:SET colorlist="Red,Green,Blue,Yellow,Orange,Black"SET extract1=$PIECE(colorlist,"#")SET extract2=$PIECE(colorlist,"#",1,4)WRITE "# =",extract1,!,"#,1,4=",extract2The following two examples use more complex delimiters.This example uses a delimiter string “#-#” to return three substrings of the string numlist.Here, the component characters of the delimiter string, “#” and “-”, can be used as data values;only the specified sequence of characters (#-#) is set aside:SET numlist="1#2-3#-#45##6#-#789"WRITE !,$PIECE(numlist,"#-#",1)WRITE !,$PIECE(numlist,"#-#",2)WRITE !,$PIECE(numlist,"#-#",3)The following example uses a non-keyboard delimiter character (in this case, the Unicodecharacter for pi), specified using the $CHAR function, and inserted into the plist string byusing the concatenate operator (_):SET a = $CHAR(960)SET colorlist="Red"_a_"Green"_a_"Blue"SET extract1=$PIECE(colorlist,a)SET extract2=$PIECE(colorlist,a,2)SET extract3=$PIECE(colorlist,a,2,3)WRITE extract1,!,extract2,!,extract3NotesUsing $PIECE to Unpack Data Values$PIECE is typically used to "unpack" data values that contain multiple fields delimited bya separator character. Typical delimiter characters include the slash (/), the comma (,), thespace ( ), and the semicolon (;). The following sample values are good candidates for usewith $PIECE:"John Jones/29 River St./Boston MA, 02095""Mumps;Measles;Chicken Pox;Diptheria""45.23,52.76,89.05,48.27"$PIECE and $LENGTH$PIECEThe two-argument form of $LENGTH returns the number of substrings in a string, basedon a delimiter. Use $LENGTH to determine the number of substrings in a string, and thenuse $PIECE to extract individual substrings, as shown in the following example:<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 283

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

Saved successfully!

Ooh no, something went wrong!