replace
Replaces characters within a string.
replace(x:string, pattern:string, replacement:string, [max=int]) -> string
Description
Section titled “Description”The replace
function returns a new string where occurrences of pattern
in x
are replaced with replacement
, up to max
times. If max
is omitted, all
occurrences are replaced.
x: string
Section titled “x: string”The subject to replace the action on.
pattern: string
Section titled “pattern: string”The pattern to replace in x
.
replacement: string
Section titled “replacement: string”The replacement value for pattern
.
max = string (optional)
Section titled “max = string (optional)”The maximum number of replacements to perform.
If the option is not set, all occurrences are replaced.
Examples
Section titled “Examples”Replace all occurrences of a character
Section titled “Replace all occurrences of a character”from {x: "hello".replace("l", "r")}
{x: "herro"}
Replace a limited number of occurrences
Section titled “Replace a limited number of occurrences”from {x: "hello".replace("l", "r", max=1)}
{x: "herlo"}