Operator Type:
Operator Scope of Action:
Operator Purpose:
Operator First Added:
Operator Last Altered:
Operator Has Optional Arguments:
Function [other Function type actions]
Item [operators of similar scope]
Data manipulation [other Data manipulation operators]
Baseline
As at baseline
String.tr(inStr[, outStr])
$MyString.tr(inStr, outStr)
This operator allows simple single character string manipulation. It computes a new string, copying each character of $MyString but converting any characters in inStr to the corresponding characters in dataOut. For example:
$MyString = $MyString.tr("a","A");
returns a copy of MyString in which every "a" is converted to "A".
Backslash characters must be quoted and escaped:
$MyString = $MyString.tr("c","\\r");
converts every "c" to a Macintosh newline characters (\r). Note the need in this context for an extra backslash escape (so Tinderbox knows the intended swap value is "\r" and not "r").
Multiple characters can be replaced:
$MyString = "Hello, world".tr("aeiou","AEIOU");
gives "HEllO, wOrld"
Note that in the later example the number of characters in inStr and outStr must match and pairs must list in order, otherwise unmatched characters will as as for the syntax below.
$MyString.tr(inStr)
If outStr is omitted or left empty, any matches to inStr are deleted from the referenced string.
$MyString = "Hello, world".tr("aeiou");
gives "Hll, wrld"
For further information, see the macOS man page for the UNIX tr command.
Performance
If using actions with a lot of .tr() calls, based on some testing in large complex docs, it may—counter-intuitively—be faster using .replace() instead.