mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
.settings
app
build
cmd
javadoc
linux
macosx
shared
examples
09. USB (Leonardo only)
1.Basics
2.Digital
3.Analog
4.Communication
5.Control
6.Sensors
7.Display
8.Strings
CharacterAnalysis
StringAdditionOperator
StringAdditionOperator.ino
StringAppendOperator
StringCaseChanges
StringCharacters
StringComparisonOperators
StringConstructors
StringIndexOf
StringLength
StringLengthTrim
StringReplace
StringStartsWithEndsWith
StringSubstring
StringToInt
StringToIntRGB
ArduinoISP
lib
tools
reference.zip
revisions.txt
windows
build.xml
create_reference.pl
fetch.sh
howto.txt
core
hardware
libraries
.classpath
.project
license.txt
readme.txt
todo.txt
All examples in /build/shared/examples/ and /libraries/ have had their extensions changed to .ino
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
/*
|
|
Adding Strings together
|
|
|
|
Examples of how to add strings together
|
|
You can also add several different data types to string, as shown here:
|
|
|
|
created 27 July 2010
|
|
modified 30 Aug 2011
|
|
by Tom Igoe
|
|
|
|
http://arduino.cc/en/Tutorial/StringAdditionOperator
|
|
|
|
This example code is in the public domain.
|
|
*/
|
|
|
|
// declare three strings:
|
|
String stringOne, stringTwo, stringThree;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
stringOne = String("stringThree = ");
|
|
stringTwo = String("this string");
|
|
stringThree = String ();
|
|
Serial.println("\n\nAdding strings together (concatenation):");
|
|
}
|
|
|
|
void loop() {
|
|
// adding a constant integer to a string:
|
|
stringThree = stringOne + 123;
|
|
Serial.println(stringThree); // prints "stringThree = 123"
|
|
|
|
// adding a constant long interger to a string:
|
|
stringThree = stringOne + 123456789;
|
|
Serial.println(stringThree); // prints " You added 123456789"
|
|
|
|
// adding a constant character to a string:
|
|
stringThree = stringOne + 'A';
|
|
Serial.println(stringThree); // prints "You added A"
|
|
|
|
// adding a constant string to a string:
|
|
stringThree = stringOne + "abc";
|
|
Serial.println(stringThree); // prints "You added abc"
|
|
|
|
stringThree = stringOne + stringTwo;
|
|
Serial.println(stringThree); // prints "You added this string"
|
|
|
|
// adding a variable integer to a string:
|
|
int sensorValue = analogRead(A0);
|
|
stringOne = "Sensor value: ";
|
|
stringThree = stringOne + sensorValue;
|
|
Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has
|
|
|
|
// adding a variable long integer to a string:
|
|
long currentTime = millis();
|
|
stringOne="millis() value: ";
|
|
stringThree = stringOne + millis();
|
|
Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has
|
|
|
|
// do nothing while true:
|
|
while(true);
|
|
} |