This version is out of date, covering development from v5.0.0 to v5.12.2. It is maintained here only for inbound reference links from elsewhere.

Jump to the current version of aTbRef.

Tinderbox Icon

String.tr("dataIn","dataOut")


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 Item   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 5.7.0

 


$MyString.tr("dataIn","dataOut")

This operator allows simple single character string manipulation. It computes a new string, copying each character of $MyString but converting any characters in dataIn to the corresponding characters in dataOut. For example:

$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.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:

"Hello, world".tr("aeiou","AEIOU") gives "HEllO, wOrld"

Note that in the later example the number of characters in dataIn and dataOUt must match and pairs must list in order, otherwise unmatched characters will as as for the syntax below.

$MyString.tr("dataIn")

If dataOut is omitted or left empty, any matches to dataIn are deleted from the target string.

"Hello, world".tr("aeiou") gives "Hll, wrld"

For further information, see the Mac OS X man page for the UNIX tr command.


Possible relevant notes (via "Similar Notes" feature):


A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : String.tr("dataIn","dataOut")