Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

$TRANSLATE

M[UMPS] by Example

Introduced in the 1990 ANSI M[UMPS] language standard.

This function returns a translated version of the value of the input-string.

Set UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Set LO="abcdefghijklmnopqrstuvwxyz"
Set X="ABCdef"

Reference   Value
$TRanslate(X,LO,UP)   "ABCDEF"
$TRanslate(X,UP,LO)   "abcdef"
$TRanslate(X,LO)   "ABC"
$TRanslate(X,UP)   "def"

Note that case conversion using $Char($ASCII(X)+32) and $Char($ASCII(X)–32) only works within the strictly bounded 128 character ASCII set. Case conversion using $TRanslate will always work, regardless of the character set being used.

Assume that X="12/26/94"

Reference   Value
$TRanslate("Yy/Mm/Dd","Mm/Dd/Yy",X)   "94/12/26"
Set X=122694
$TRanslate("efabcd","abcdef",X)
  "941226"

Note: in this example, start with the string "efabcd". Replace all "a"s with the first character of the value of X, all "b"s with the second character, et cetera.

Set (FORWARD,BACKWARD)=""
For K=0:1:255 Set FORWARD=FORWARD_$Char(K)
For K=0:1:255 Set BACKWARD=$Char(K)_BACKWARD
$TRanslate(FORWARD,BACKWARD,"ABCDE") = "EDCBA"

$TRanslate(string,$TRanslate(string,"0123456789")) will return only the digits that occur in the value of string. Note that this result is not necessarily the same as the value of +string.

Set X="abc123cde654ghi"
$TRanslate(X,$TRanslate(X,"1234567890"))
returns 123654

The "inner" $TRanslate returns a value that is the original value of X, with all digits removed.
The "outer" $TRanslate returns a value that is the original value of X, with all characters removed that occur in the return value of the inner $TRanslate.
Effectively, this combination of two nested $TRanslates will return only those characters from the original value of X that occur in the value of the second parameter of in "inner" $TRanslate.

Examples with naked references:

$TRanslate(VALUE,OLD)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$TRanslate(^(5,6),^(7,8))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. store ^(3,4) = ^ABC(1,5,7,3,4)
; naked indicator is now: ^ABC(1,5,7,3,

$TRanslate(VALUE,OLD,NEW)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$TRanslate(^(5,6),^(7,8),^(9,10))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. fetch ^(9,10) = ^ABC(1,5,7,9,10)
; 4. store ^(3,4) = ^ABC(1,5,7,9,3,4)
; naked indicator is now: ^ABC(1,5,7,9,3,

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

The information in this page is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 12-Sep-2014, 13:34:35.

For comments, contact Ed de Moel (demoel@jacquardsystems.com)