translate()

将一组字符(“searchList”)替换为给定字符串中的另一组字符(“replacementList”)。 此函数在“searchList”中搜索字符,并将其替换为“replacementList”中的相应字符

语法

translate(searchList,replacementList,source)

详细了解语法约定

参数

客户 类型​​ 必需 说明
searchList string 应被替换的字符的列表。
replacementList string 应替换“searchList”中字符的字符的列表。
source string 一个要搜索的字符串。

返回

将“replacementList”中出现的所有字符替换为“searchList”中的相应字符后得到的 source

示例

输入 输出
translate("abc", "x", "abc") "xxx"
translate("abc", "", "ab") ""
translate("krasp", "otsku", "spark") "kusto"