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.

is an asterisk, $EXTRACT returns the substring beginning with the from character throughthe end of the string. If to is an integer greater than the length of the string, $EXTRACT alsoreturns the substring beginning with the from character through the end of the string. If to isless than from, $EXTRACT returns a null string.$EXTRACT ExamplesThe following example returns “D”, the fourth character in the string:SET x="ABCDEFGHIJK"WRITE $EXTRACT(x,4)The following example returns “K”, the last character in the string:SET x="ABCDEFGHIJK"WRITE $EXTRACT(x,*)In the following example, all the $EXTRACT functions return “J” the next-to-last characterin the string:SET n=-1SET m=1SET x="ABCDEFGHIJK"WRITE !,$EXTRACT(x,*-1)WRITE !,$EXTRACT(x,*-m)WRITE !,$EXTRACT(x,*+n)WRITE !,$EXTRACT(x,*-1,*-1)Note that a minus or plus sign is needed between the asterisk and the integer variable.The following example shows that the one-argument format is equivalent to the two-argumentformat when the from value is “1”. Both $EXTRACT functions return “H”.SET x="HELLO"WRITE !,$EXTRACT(x)WRITE !,$EXTRACT(x,1)The following example returns a substring “THIS IS” which is composed of the first throughseventh characters.SET x="THIS IS A TEST"WRITE $EXTRACT(x,1,7)The following example also returns the substring “THIS IS”. When the from variable containsa value less than 1, $EXTRACT treats that value as 1. Thus, the following example returnsa substring composed of the first through seventh characters.SET X="THIS IS A TEST"WRITE $EXTRACT(X,-1,7)The following example returns the last four characters of the string:$EXTRACT<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 205

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

Saved successfully!

Ooh no, something went wrong!