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

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

Adding new version

File size: 1.1 KB
Line 
1/*
2  String charAt() and setCharAt()
3
4 Examples of how to get and set characters 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/StringCharacters
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  Serial.println("\n\nString  charAt() and setCharAt():");
23}
24
25void loop() {
26  // make a string to report a sensor reading:
27  String reportString = "SensorReading: 456";
28  Serial.println(reportString);
29
30  // the reading's most significant digit is at position 15 in the reportString:
31  char mostSignificantDigit = reportString.charAt(15);
32
33  String message = "Most significant digit of the sensor reading is: ";
34  Serial.println(message + mostSignificantDigit);
35
36  // add blank space:
37  Serial.println();
38
39  // you can alo set the character of a string. Change the : to a = character
40  reportString.setCharAt(13, '=');
41  Serial.println(reportString);
42
43  // do nothing while true:
44  while (true);
45}
46
Note: See TracBrowser for help on using the repository browser.