Translate (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (match syntax diagram to revised template; fix tags and links)
Line 1: Line 1:
{{Template:String:Translate subtitle}}
{{Template:String:Translate subtitle}}


The <var>Translate</var> method takes a string or longstring input and outputs a copy of it in which
<var>Translate</var> 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.  <var>Translate</var> takes a <var>[[characterMap_class|CharacterMap]]</var> object as input which maps In ("input table") characters to Out ("output table") characters.
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.


<var>Translate</var> has many similarities to the Sirius function $LSTR_TRANSLATE, which is described in the '''''Sirius Functions Reference Manual'''''.
The <var>Translate</var> method takes a <var>CharacterMap</var> object as input. A [[aracterMap class|CharacterMap]] object maps In ("input table")
characters to Out ("output table") characters.
==Syntax==
==Syntax==
{{Template:String:Translate syntax}}
{{Template:String:Translate syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%outStr</th>
<tr><th>%outString</th>
<td>A string or <var>Longstring</var> to receive the translated input string.                               </td></tr>
<td>A string or to receive the translated input <var class="term>string</var>.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The input string or <var>Longstring</var>.                                                               </td></tr>
<td>The method object input string.</td></tr>
<tr><th>charMap</th>
<tr><th>characterMap</th>
<td>A <var>CharacterMap</var> object variable which indicates the output characters to which specified input characters are to be mapped.</td></tr>
<td>A <var>[[characterMap_class|CharacterMap]]</var> object variable which defines the relationship (mapping) between input and output characters.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
*For information about constructing a <var>CharacterMap</var> object, see [[CharacterMap New constructor]].
<ul><li>For information about constructing a <var>CharacterMap</var> object, see <var>[[New_(CharacterMap_constructor)|CharacterMap New constructor]]</var>.</ul>
 
==Examples==
==Examples==
<ol><li>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:
<p class="code">begin
  %map is object characterMap
  %ls is longstring


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:
  %map = new(in='ac',out='Bd')
<p class="code">Begin
  %ls = 'aaaccc'
%map is object characterMap
  printText {~} = '{%ls:translate(%map)}'
%ls is longstring
end
 
%map = new(in='ac',out='Bd')
%ls = 'aaaccc'
[[Intrinsic classes#printtext|printText]] {~} = '{%ls:translate(%map)}'
End
 
</p>
</p>
The result is:
The result is:
<p class="output">%ls:translate(%tr) = 'BBBddd'
<p class="output">%ls:translate(%tr) = 'BBBddd'
</p></ol>


</p>
==See also==
==See also==
<ul><li><var>Translate</var> has many similarities to the Sirius function $LSTR_TRANSLATE, which is described in the <b><i>"Sirius Functions Reference Manual"</i></b>.
<li>For details of the <var>printtext</var> statement, please see <var>[[Intrinsic classes#printtext|printText]]</var></ul>
{{Template:String:Translate footer}}
{{Template:String:Translate footer}}

Revision as of 06:41, 2 February 2011

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

Examples

  1. 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

  • Translate has many similarities to the Sirius function $LSTR_TRANSLATE, which is described in the "Sirius Functions Reference Manual".
  • For details of the printtext statement, please see printText