source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/08.Strings/StringReplace/StringReplace.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 1.3 KB
Line 
1/*
2  String replace()
3
4 Examples of how to replace characters or substrings of a string
5
6 created 27 July 2010
7 modified 2 Apr 2012
8 by Tom Igoe
9
10 http://www.arduino.cc/en/Tutorial/StringReplace
11
12 This example code is in the public domain.
13 */
14
15void setup() {
16  // Open serial communications and wait for port to open:
17  Serial.begin(9600);
18  while (!Serial) {
19    ; // wait for serial port to connect. Needed for native USB port only
20  }
21
22  // send an intro:
23  Serial.println("\n\nString  replace:\n");
24  Serial.println();
25}
26
27void loop() {
28  String stringOne = "<html><head><body>";
29  Serial.println(stringOne);
30  // replace() changes all instances of one substring with another:
31  // first, make a copy of th original string:
32  String stringTwo = stringOne;
33  // then perform the replacements:
34  stringTwo.replace("<", "</");
35  // print the original:
36  Serial.println("Original string: " + stringOne);
37  // and print the modified string:
38  Serial.println("Modified string: " + stringTwo);
39
40  // you can also use replace() on single characters:
41  String normalString = "bookkeeper";
42  Serial.println("normal: " + normalString);
43  String leetString = normalString;
44  leetString.replace('o', '0');
45  leetString.replace('e', '3');
46  Serial.println("l33tspeak: " + leetString);
47
48  // do nothing while true:
49  while (true);
50}
Note: See TracBrowser for help on using the repository browser.