
The translate() function locates characters in a string and replaces them with other characters. It can also be used to remove characters from a string.
string translate(string, string, string)Three strings. The first string contains the characters to be evaluated. The second string contains the characters to be matched. The third string contains the characters to replace the characters in the first argument that match characters in the second argument. While the third argument is required, it can be empty, in which case, the result will be the first argument with all of the characters that match the second argument removed.
A string in which characters in the first argument that match characters in the second argument are replaced by characters in the third argument. So, for example, translate(`treats:donuts',':','/') produces the string treats/donuts.
If a character in the first argument does not occur in the second argument, it is copied to the result unchanged. If a character from the first argument matches a character at position X in the second argument and the list of replacement characters in the third argument is length X or longer, the replacement character is substituted for the matched character in the result. If a character from the first argument matches a character at position X in the second argument, but the list of replacement characters in the third argument is less than length X, the matched character is deleted. If a character in the second argument appears more than once, the first occurrence determines the replacement character.
|
Comments?
devdoc-feedback@netscape.com |