Name
translate() Function — Allows you to convert individual characters in a string from one value to another. In many languages, this function is powerful enough to convert characters from one case to another.
Synopsis
stringtranslate(stringstringstring)
Inputs
Three strings. The first is the original, untranslated string, and the second and third strings define the characters to be converted.
Output
The original string, translated as follows:
If a character in the original string appears in the second argument string, it is replaced with the corresponding character in the third argument string. In other words, if the character
Jappears in the original string andJappears as the fourth character in the second argument string, theJis replaced with the fourth character from the third argument string. (Don’t worry, we’ll have some examples to clear this up in just a minute.)If a character in the original string appears in the second argument string and there is no corresponding character in the third argument string (the second argument string is longer than the third), then that character is deleted. In other words, if the character
Jappears in the original string, andJappears as the fourth character in the second argument string, and the third argument string is three characters long, theJis deleted.If a character in the second argument string appears more than once, the first occurrence determines the replacement character.
If the third argument string is longer than the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access