String class
replace()
The String replace()
function allows you to replace all instances of a given character with another character. You can also use replace to replace substrings of a string with a different substring. This modified the object, not a copy.
// SYNTAX
string.replace(substring1, substring2)
// PROTOTYPES
String& replace(char find, char replace);
String& replace(const String& find, const String& replace);
Parameters:
- string: the string which will be modified - a variable of type String
- substring1: searched for - another variable of type String (single or multi-character), char or const char (single character only)
- substring2: replaced with - another variable of type String (single or multi-character), char or const char (single character only)
Returns: A reference to the String object (*this
).