.replace() method returns a string with a portion replaced by another string, or a portion of another string.
baseString.replace(pos, len, str, subpos, sublen)
baseStringis the string whose contents are being replaced.
posis the zero-based starting position of the replacement.
lenis the number of characters to be replaced.
stris the replacement string.
subposis optional, and is the zero-based starting point of the replacement characters used from
sublenis optional, and is the number of replacement characters used from
sublen aren’t specified, the entire
str is used for the replacement.
The following example replaces a portion of a base string with a portion of another string:
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn C++ on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification