The format for the $TRANSLATE function is:
$TR[ANSLATE](expr1[,expr2[,expr3[,expr4]]])
If the fourth argument is invalid/null, $TRANSLATE() operates in the standard fashion.
Irrespective of the settings of VIEW "BADCHAR" and $ZCHSET, $ZTRANSLATE() interprets argument as a sequence of bytes (rather than a sequence of characters) and performs all byte-oriented $TRANSLATE() operations. For more information, refer to a??$ZTRanslate()a??.
$TRANSLATE() provides a tool for tasks such as changing case and doing encryption. For examples of case translation, refer to the ^%LCASE and ^%UCASE utility routines.
The $TRANSLATE() algorithm can be understood as follows:
$TRANSLATE() evaluates each character in the first expression, comparing it character by character to the second expression looking for a match. If there is no match in the second expression, the resulting expression contains the character without modification.
When it locates a character match, $TRANSLATE() uses the position of the match in the second expression to identify the appropriate replacement for the original expression. If the second expression has more characters than the third expression, $TRANSLATE() replaces the original character with a null, thereby deleting it from the result. By extension of this principle, if the third expression is missing, $TRANSLATE() deletes all characters from the first expression that occur in the second expression.
GTM>write $translate("ABC","CB","1") A1 GTM>
![]() | Note |
---|---|
While this example provides an explanation for the work done by $TRANSLATE(), it does not necessarily correspond to how GT.M implements $TRANSLATE(). |
GTM>write $translate("A","AA","BC") B GTM>
GTM>write $translate("BACKUP","AEIOU") BCKP GTM>
GTM>write $translate("ENCYCLOPEDIA","AEIOU","","L") NCYCLOPEDIA GTM>write $translate("ENCYCLOPEDIA","AEIOU","","R") ENCYCLOPED GTM>write $translate("ENCYCLOPEDIA","AEIOU","","B") NCYCLOPED GTM>