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> FunctionsExamplesIn this example, the second SET command uses $TRANSLATE to remove the commas andproduce a valid number, 1462543.SET x="1,462,543"WRITE !,"before translation ",xSET x=$TRANSLATE(x,",")WRITE !,"after translation ",xThis example shows use of the three-argument $TRANSLATE and nested $TRANSLATEfunctions. The outermost $TRANSLATE function returns the string "06/23/93". The original"1" is replaced by "9" and the original occurrences of "9" are deleted. The hyphens are replacedby slashes.SET x="06-23-1993"WRITE !,"before translation ",xSET x=$TRANSLATE($TRANSLATE(x,"199","9"),"-","/")WRITE !,"after translation ",xIf a character appears multiple times in the identifier, the first (leftmost) occurrence of thecharacter is used to position the replacement. As a result, you cannot use $TRANSLATE toremove multiple occurrences of a character from a string. For example, if the innermost$TRANSLATE in the previous example were specified as:SET x = $TRANSLATE(x,"1993","93")It would result in the undesirable value "06/2/933". In the original string ("06-23-1993"), the"1" is replaced by "9" and each occurrence of "9" is replaced by "3". The original occurrencesof "3" are removed since "3" is an excess character in identifier. This is a case of attemptingto use $TRANSLATE to perform string, rather than character replacement.See Also• $EXTRACT function• $PIECE function• $REVERSE function• $ZCONVERT function308 <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!