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 thesearchsubstring.
Returns
- String: A new string with all occurrences of
searchreplaced byreplace.
Example
string::replace("hello world", "world", "there")This function is useful for modifying strings by substituting specific substrings with desired replacements.