z/OS TSO/E REXX Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


TRANSLATE

z/OS TSO/E REXX Reference
SA32-0972-00

Read syntax diagramSkip visual syntax diagram
>>-TRANSLATE(string--------------------------------------------->

>--+----------------------------------------+--)---------------><
   '-,-+--------+-+-----------------------+-'      
       '-tableo-' '-,-+--------+-+------+-'        
                      '-tablei-' '-,pad-'          

returns string with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in string. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in string is used. The result string is always the same length as string.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase az to uppercase AZ), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults to XRANGE('00'x,'FF'x), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:
TRANSLATE('abcdef')                    ->    'ABCDEF'
TRANSLATE('abbc','&','b')              ->    'a&&c'
TRANSLATE('abcdef','12','ec')          ->    'ab2d1f'
TRANSLATE('abcdef','12','abcd','.')    ->    '12..ef'
TRANSLATE('APQRV',,'PR')               ->    'A Q V'
TRANSLATE('APQRV',XRANGE('00'X,'Q'))   ->    'APQ  '
TRANSLATE('4123','abcd','1234')        ->    'dabc'

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014