Does a character by character translation. This is equivalent to Perl’s tr/// construct. From-string is a string specification of a character set, and to-string is another character set. translate converts input character by character, according to the sets. For instance,
translate("any string", "a-z", "A-Z")will convert “any string” to all uppercase: “ANY STRING”.
Like Perl, character ranges are not allowed to be “backwards”. The following is not legal:
translate(“any string”, “a-z”, “z-a”)
Unlike Perl’s tr///, translate doesn’t return the number of characters translated.
If delete: is #t, any characters in the from-string that don’t have matching characters in the to-string are deleted. The following will remove all vowels from a string and convert periods to commas:
translate("any string", ".aeiou", ",", delete: #t)Delete: is #f by default. If delete: is #f and there aren’t enough characters in the to-string, the last character in the to-string is reused as many times as necessary. The following converts several punctuation characters into spaces:
translate("any string", ",./:;[]{}()", " ");Start: and end: indicate which part of input to translate. They default to the entire string.
Note: translate is always case sensitive.
open
| input | An instance of <string>. The string to translate. |
| from-set | An instance of <string>. String specification of a character set. |
| to-set | An instance of <string>. Another character set. |
| delete: | An instance of <object>. If true, any characters in the from-string that don’t have matching characters in the to-string are deleted. The default is #f. |
| start: | An instance of <integer>. Where to start parsing the string. The default is 0. |
| end: | An instance of <integer> or #f. If defined, where to stop parsing the string. The default is #f. |
| output | An instance of <string>. |