translate()translate()

将一组字符(“searchList”)替换为给定字符串中的另一组字符(“replacementList”)。Replaces a set of characters ('searchList') with another set of characters ('replacementList') in a given a string. 此函数在“searchList”中搜索字符,并将其替换为“replacementList”中的相应字符The function searches for characters in the 'searchList' and replaces them with the corresponding characters in 'replacementList'

语法Syntax

translate(searchList, replacementList, text)translate(searchList, replacementList, text)

参数Arguments

  • searchList:应被替换的字符的列表searchList: The list of characters that should be replaced
  • replacementList:应替换“searchList”中字符的字符的列表replacementList: The list of characters that should replace the characters in 'searchList'
  • text:要搜索的字符串text: A string to search

返回Returns

将“replacementList”中出现的所有字符替换为“searchList”中的相应字符后得到的 texttext after replacing all ocurrences of characters in 'replacementList' with the corresponding characters in 'searchList'

示例Examples

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