Programmer Guide/Command Reference/TRANSLATE: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
  <var>#str</var> := TRANSLATE <var>string</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ]
{{PG_StringCommands}}
  <var>#str</var> := TRANSLATE <var>variable</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ] /Variable
  <var>#str</var> := TRANSLATE [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>string</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ]
  <var>#str</var> := TRANSLATE <var>table</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ] /Table
  <var>#str</var> := TRANSLATE /Variable [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>variable</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ]
  <var>#str</var> := TRANSLATE /Table [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>table</var> <var>sub<sub>1</sub></var> <var>trn<sub>1</sub></var> [ <var>sub<sub>X</sub></var> <var>trn<sub>X</sub></var> &hellip; ]


The {{STx}} command <code>TRANSLATE</code> returns a modified copy of its <var>string</var> argument, the modification being that all occurrences of the string <var>sub<sub>N</sub></var> are replaced by the string <var>trn<sub>N</sub></var>.
The {{STx}} command <code>TRANSLATE</code> returns a modified copy of its argument, the modification being that all occurrences of the string <var>sub<sub>N</sub></var> are replaced by the string <var>trn<sub>N</sub></var>.


If the option <var>/Variable</var> is specified, <var>string</var> is treated as the name of a variable whose contents will be used as the string to <code>TRANSLATE</code>. If the option <code>/Table</code> is specified, <var>string</var> is treated as the name of a table item whose contents will be used as the string to <code>TRANSLATE</code>.
In its first form, the argument <var>string</var> is taken as a string literal. With option <code>/Variable</code>, the command will return the modified ''content'' of the {{Stx}} variable <var>variable</var>, while with option <code>/Table</code>, <code>TRANSLATE</code> will return the modified contents of an {{STX}} table denoted by the <var>table</var> argument. In either case the content of the respective variable or table will be left untouched.


<pre>
It is amazingly good practice to always use the [[Programmer_Guide/Command_Reference_Options/-|"end of options" option, <code>/-</code>]]. If it is missing, {{Stx}} will mistake any further arguments starting with a slash for a (probably invalid) option.
#str := TRANSLATE 'I am getting tired of going to bed early' 'ing' 'ed'
 
um $#str
#str := TRANSLATE 'I am getting tired of going to bed early' 'ing' 'ed' 'bed' 'work'
</pre>
um $#str

Latest revision as of 11:27, 4 March 2016

#str := TRANSLATE /- string sub1 trn1 [ subX trnX … ]
#str := TRANSLATE /Variable /- variable sub1 trn1 [ subX trnX … ]
#str := TRANSLATE /Table /- table sub1 trn1 [ subX trnX … ]

The STx command TRANSLATE returns a modified copy of its argument, the modification being that all occurrences of the string subN are replaced by the string trnN.

In its first form, the argument string is taken as a string literal. With option /Variable, the command will return the modified content of the STx variable variable, while with option /Table, TRANSLATE will return the modified contents of an STx table denoted by the table argument. In either case the content of the respective variable or table will be left untouched.

It is amazingly good practice to always use the "end of options" option, /-. If it is missing, STx will mistake any further arguments starting with a slash for a (probably invalid) option.

#str := TRANSLATE 'I am getting tired of going to bed early' 'ing' 'ed' 'bed' 'work'
um $#str

Navigation menu

Personal tools