Name
replace — Replace all occurrences of a substring in a string with a new substring
Usage
String.replace(str, old, new)
: Stringstr
: Stringold
: Stringnew
Description
Returns a string in which all occurrences of the substring
old
in the string
str
have been replaced with the substring
new
. The return value is a new string;
str
itself remains unmodified.
Returns invalid
if any of the arguments
can’t be converted to a string.
Examples
String.replace("Hello, world!", "l", "p")
returns string "Heppo,
worpd!"
String.replace("Hello, world!", "ll", "y")
returns string "Heyo,
world!"
String.replace("aaaaa", "aa", "b")
returns string "bba"
String.replace(123456, 34, 43)
returns string "124356"
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.