Translate (String function)

From m204wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Apply a Character Map to the method object string (String class)


Translate takes a string 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 takes a CharacterMap object as input which maps In ("input table") characters to Out ("output table") characters.

Syntax

%outString = string:Translate( characterMap)

Syntax terms

%outString A string or to receive the translated input string.
string The method object input string.
characterMap A CharacterMap object variable which defines the relationship (mapping) between input and output characters.

Usage notes

  • For information about constructing a CharacterMap object, see New, the CharacterMap constructor.

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