Translate (String function)

From m204wiki
Revision as of 21:55, 20 August 2010 by JAL (talk | contribs) (Created page with "The Translate method takes a string or longstring input and outputs a copy of it in which any of the input characters that are specified in a character mapping object ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Translate method takes a string or longstring input and outputs a copy of it in which any of the input characters that are specified in a character mapping object are replaced with the characters to which they are mapped by the object.

Translate has many similarities to the Sirius function $LSTR_TRANSLATE, which is described in the Sirius Functions Reference Manual.

The Translate method takes a CharacterMap object as input. A CharacterMap object maps In ("input table") characters to Out ("output table") characters.

Translate syntax

  %outStr = string:translate(charMap)                                                            

Syntax Terms

%outStr
A string or Longstring to receive the translated input string.
string
The input string or Longstring.
charMap
A CharacterMap object variable which indicates the output characters to which specified input characters are to be mapped.

Usage Notes

Examples

In the following request, a's are translated to B's, and c's are translated to d's, as dictated by the character mapping in %map:

   Begin                                                                                         
   %map is object characterMap 
   %ls is longstring                                               
                                                                   
   %map = new(in='ac',out='Bd')                                    
   %ls = 'aaaccc'                                                  
   printtext {~} = '{%ls:translate(%map)}' 
   End                                                             
                                                                   

The result is:

   %ls:translate(%tr) = 'BBBddd'                                   
                                                                   

See also

List of Intrinsic String Methods