In
a given string, replaces the occurrence of any of the characters
of a second given string with the corresponding characters of a
third given string or removes the occurrence of characters of a
second given string if no corresponding character exists in the
third given string.
Syntax
translate(string, string, string)
Parameters
Three
string
values
separated by commas. The first string is the string in which characters
are replaced. The second string contains the characters whose occurrences
in the first string are replaced. The third string contains the
replacement characters that correspond with the characters in the
second string.
The characters in the second string correspond
with the characters in the third string that have the same index:
-
If the second string is longer than the third string, the
characters in the second string that have an index that is greater
than the length of the third string have no corresponding characters.
-
If the third string is longer than the second string, the
characters in the third string that have an index that is greater
than the length of the second string are ignored.
-
If a character occurs more than once in the second string,
the first occurrence of the character determines how that character
is replaced in the first string.
Returns
A
string that contains the first parameter with the replaced characters.
Example
The
following expression includes a second parameter that includes characters that
all correspond with a character in the third parameter. The expression returns
BAr
:
translate("bar","abc","ABC")
The
following expression includes a second parameter that is longer
than the third parameter. The expression returns
AAA
:
translate("--aaa--","abc-","ABC")
The
following expression includes a second parameter that includes multiple occurrences
of a character. The expression returns
BAr
:
translate("bar", "aba", "ABC")
|
|
|