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.

$EXTRACTSET x="ABCD"SET $EXTRACT(x,1)="Z"WRITE xThe following example replaces “ABCD” with “GHIJ”.SET x="ABCD"SET $EXTRACT(x,1,4)="GHIJ"WRITE xIn the following example, assume that variable x does not exist.KILL xSET $EXTRACT(x,1,4)="ABCD"WRITE xThe SET command creates variable x and assigns it the value “ABCD”.You can also use SET $EXTRACT to add or remove character positions in a target variable.To add character positions, specify a from value or a from,to range that exceeds the lengthof the target variable. For example, if x contains “ABCD,” the following $EXTRACTfunction inserts the value “Z” in the tenth position:SET x="ABCD"SET $EXTRACT(x,10)="Z"WRITE xBecause 10 exceeds the number of characters in x, SET $EXTRACT fills the intervening positions(that is, position 5 through 9) with spaces. As a result, x now contains the value“ABCD^^^^^Z” , where ^ indicates a space.The following example inserts the value “Y” in the eleventh position, but no additionalcharacters in positions 12 and 13.SET x="ABCD"SET $EXTRACT(x,11,13)="Y"WRITE xAs a result, the original x value (“ABCD”) is changed to “ABCD^^^^^^Y” and x now has alength of 11. (If the assigned value “Y” were three characters, instead of just one, positions12 and 13 would be filled as well.)To remove character positions, extract a character or range and replace it with the null string.The following results in a two-character string with the value “AD”:SET x="ABCD"SET $EXTRACT(x,2,3)=""WRITE x<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 207

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

Saved successfully!

Ooh no, something went wrong!