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

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1009 bytes
Line 
1/*
2  String length() and trim()
3
4 Examples of how to use length() and trim() in 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/StringLengthTrim
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  length() and trim():");
24  Serial.println();
25}
26
27void loop() {
28  // here's a String with empty spaces at the end (called white space):
29  String stringOne = "Hello!       ";
30  Serial.print(stringOne);
31  Serial.print("<--- end of string. Length: ");
32  Serial.println(stringOne.length());
33
34  // trim the white space off the string:
35  stringOne.trim();
36  Serial.print(stringOne);
37  Serial.print("<--- end of trimmed string. Length: ");
38  Serial.println(stringOne.length());
39
40  // do nothing while true:
41  while (true);
42}
Note: See TracBrowser for help on using the repository browser.