String replace Function

The Stringreplace() 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.

Hardware Required

  • Arduino Board

Circuit

There is no circuit for this example, though your board must be connected to your computer via USB and the serial monitor window of the Arduino Software (IDE) should be open.

circuit

Code

Caution: If you try to replace a substring that's more than the whole String itself, nothing will be replaced. For example:

String stringOne = "<html><head><body>";
String stringTwo = stringOne.replace("<html><head></head><body></body></html>", "Blah");

In this case, the code will compile, but stringOne will remain unchanged, since the replacement substring is more than the String itself.

See Also

Last Revision 2018/03/27 by SM