Replace
Within a string, replace the first occurrence of a pattern by another string.
Description
Returns a new string in which the first match of pattern
has been replaced by replacement
. Both pattern
and replacement
are strings.
Uses the replace
JavaScript function.
See <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String" target="_blank">string object</a>.
Inputs
- s (String): The original string.
- pattern (String): The string to replace.
- replacement (String): The string to use as a replacement.
Outputs
- new string (String): The string with the pattern replaced.