String Replace
The string::replace
function replaces all occurrences of a specified substring within a string with a new substring.
Syntax
string::replace(<original>, <search>, <replace>)
Parameters
original
: The input string where replacements will occur.search
: The substring to be replaced.replace
: The new substring that will replace occurrences of thesearch
substring.
Returns
- String: A new string with all occurrences of
search
replaced byreplace
.
Example
string::replace("hello world", "world", "there")
This function is useful for modifying strings by substituting specific substrings with desired replacements.