O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

replace — Replace all occurrences of a substring in a string with a new substring

Usage

String.replace(str, old, new)

str : String

old : String

new : String

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"

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required