Goto main content

strtr_list

Translate substrings.

STRTR_LIST

NAME

strtr_list - Translate substrings or replace substrings.

SYNOPSIS

strtr_list(string,from,to)

DESCRIPTION

This function returns a copy of string where all occurrences of each character in from have been translated to the corresponding character in to, i.e., every occurrence of $from[$n] has been replaced with $to[$n], where $n is a valid offset in both arguments.

PARAMETERS

string
The string being translated.
from
The array being translated to to.
to
The array replacing from.

RETURN

Returns the translated string.

EXAMPLES

in:  res=<{strtr_list("aa123bb456xx789",["a","b","x"],["cc","ddd","yyyy"])}>.
out: res=cccc123dddddd456yyyyyyyy789.

in:  res=<{strtr_list("aa123bb456xx789",["a","b","x"],["cc","ddd","yyyy"])}>.
out: res=cccc123dddddd456yyyyyyyy789.

in:  res=<{strtr_list("hello world, hi hhh",["h","hi","hello"],["-","hello","hi"])}>.
out: res=hi world, hello ---.

in:  res=<{strtr_list("aa123bb456xx789",["a","b","x"],["cc","ddd","yyyy"])}>.
out: res=cccc123dddddd456yyyyyyyy789.

SEE ALSO

{{ include("includes/strings.sn") }}

AUTHOR

Written by Pusnei Sergey, <sergey@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.