Translate (String function): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 1: | Line 1: | ||
{{Template:String:Translate subtitle}} | {{Template:String:Translate subtitle}} | ||
The Translate method takes a string or longstring input and outputs a copy of it in which | 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 | 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. | 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'''''. | 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 [[aracterMap class|CharacterMap]] object maps In ("input table") | The Translate method takes a CharacterMap object as input. A [[aracterMap class|CharacterMap]] object maps In ("input table") | ||
characters to Out ("output table") characters. | characters to Out ("output table") characters. | ||
==Syntax== | ==Syntax== | ||
{{Template:String:Translate syntax}} | {{Template:String:Translate syntax}} | ||
Line 20: | Line 20: | ||
<td>A CharacterMap object variable which indicates the output characters to which specified input characters are to be mapped.</td></tr> | <td>A CharacterMap object variable which indicates the output characters to which specified input characters are to be mapped.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
*For information about constructing a CharacterMap object, see [[CharacterMap New constructor]]. | *For information about constructing a CharacterMap object, see [[CharacterMap New constructor]]. | ||
==Examples== | ==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: | 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 | Begin | ||
%map is object characterMap | %map is object characterMap | ||
%ls is longstring | %ls is longstring | ||
%map = new(in='ac',out='Bd') | %map = new(in='ac',out='Bd') | ||
%ls = 'aaaccc' | %ls = 'aaaccc' | ||
[[Intrinsic classes#printtext|printText]] {~} = '{%ls:translate(%map)}' | [[Intrinsic classes#printtext|printText]] {~} = '{%ls:translate(%map)}' | ||
End | End | ||
The result is: | The result is: | ||
%ls:translate(%tr) = 'BBBddd' | %ls:translate(%tr) = 'BBBddd' | ||
===See also=== | ===See also=== | ||
[[List of intrinsic String methods]] | [[List of intrinsic String methods]] | ||
[[Category:Intrinsic String methods|Translate function]] | [[Category:Intrinsic String methods|Translate function]] | ||
[[Category:Intrinsic methods]] | [[Category:Intrinsic methods]] |
Revision as of 14:04, 19 January 2011
Apply a Character Map to the method object string (String class)
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.
Syntax
%outString = string:Translate( characterMap)
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
- For information about constructing a CharacterMap object, see CharacterMap New 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'