Translate (String function): Difference between revisions
m (match syntax diagram to revised template; fix tags and links) |
m (→Examples) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:String:Translate subtitle}} | {{Template:String:Translate subtitle}} | ||
<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. | <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 <var>In</var> ("input table") characters to <var>Out</var> ("output table") characters. | ||
==Syntax== | ==Syntax== | ||
Line 8: | Line 8: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%outString</th> | <tr><th>%outString</th> | ||
<td>A string or to receive the translated input <var class="term>string</var>.</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 method object input string.</td></tr> | <td>The method object input string.</td></tr> | ||
Line 16: | Line 16: | ||
==Usage notes== | ==Usage notes== | ||
<ul><li>For information about constructing a <var>CharacterMap</var> object, see <var>[[New_(CharacterMap_constructor)| | <ul> | ||
<li>For information about constructing a <var>CharacterMap</var> object, see <var>[[New_(CharacterMap_constructor)|New]]</var>, the <var>CharacterMap</var> constructor. | |||
</ul> | |||
==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 <code>%map</code>: | |||
<p class="code">begin | <p class="code">begin | ||
%map is object characterMap | %map is object characterMap | ||
Line 26: | Line 28: | ||
%map = new(in='ac',out='Bd') | %map = new(in='ac',out='Bd') | ||
%ls = 'aaaccc' | %ls = 'aaaccc' | ||
printText {~} = '{%ls:translate(%map)}' | [[PrintText statement|printText]] {~} = '{%ls:translate(%map)}' | ||
end | end | ||
</p> | </p> | ||
The result is: | The result is: | ||
<p class="output">%ls:translate(%tr) = 'BBBddd' | <p class="output">%ls:translate(%tr) = 'BBBddd' | ||
</p | </p> | ||
==See also== | ==See also== | ||
<ul><li><var>Translate</var> has many similarities to the Sirius function | <ul><li><var>Translate</var> has many similarities to the Sirius function <var>[[$Lstr_Translate]]</var>.</ul> | ||
{{Template:String:Translate footer}} | {{Template:String:Translate footer}} |
Latest revision as of 22:42, 5 November 2012
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
- Translate has many similarities to the Sirius function $Lstr_Translate.