While compiling the sample source (Arduino v1.0) 8. Strings -> StringReplace:
StringReplace.cpp: In function 'void loop()':
StringReplace:22: error: conversion from 'void' to non-scalar type 'String' requested
StringReplace:28: error: conversion from 'void' to non-scalar type 'String' requested
StringReplace:29: error: no match for 'operator=' in 'leetString = leetString.String::replace('e', '3')'
C:\Users...\Documents\Arduino\arduino-1.0\hardware\arduino\cores\arduino/WString.h:83: note: candidates are: String& String::operator=(const String&)
C:\Users...\Documents\Arduino\arduino-1.0\hardware\arduino\cores\arduino/WString.h:84: note: String& String::operator=(const char*)
The String class has been reimplemented as well, by Paul Stoffregen. This
new version is more memory-efficient and robust. Some functions which
previously returned new string instances (e.g. trim() and toUpperCase())
have been changed to instead modify strings in place.
It would appear that the example sketches haven't been updated.
This version works:
/*
String replace()
Examples of how to replace characters or substrings of a string
created 27 July 2010
by Tom Igoe
http://arduino.cc/en/Tutorial/StringReplace
This example code is in the public domain.
*/
void setup() {
Serial.begin(9600);
Serial.println("\n\nString replace:");
}
void loop() {
String stringOne = "<html><head><body>";
Serial.println(stringOne);
// replace() changes all instances of one substring with another:
stringOne.replace("<", "</");
Serial.println(stringOne);
// you can also use replace() on single characters:
String normalString = "bookkeeper";
Serial.println("normal: " + normalString);
normalString.replace('o', '0');
normalString.replace('e', '3');
Serial.println("l33tspeak: " + normalString);
// do nothing while true:
while(true);
}