String Appending Operators
Just as you can concatenate Strings with other data objects using the StringAdditionOperator, you can also use the +=
operator and the concat()
method to append things to Strings. The +=
operator and the concat()
method work the same way, it's just a matter of which style you prefer. The two examples below illustrate both, and result in the same String:
String stringOne = "A long integer: ";
// using += to add a long variable to a string:
stringOne += 123456789;
or
String stringTwo = "A long integer: ";
// using concat() to add a long variable to a string:
stringTwo.concat(123456789);
In both cases, stringOne
equals "A long integer: 123456789". Like the +
operator, these operators are handy for assembling longer strings from a combination of data objects.
Hardware Required
- Arduino Board
Circuit
There is no circuit for this example, though your board must be connected to your computer via USB and the serial monitor window of the Arduino Software (IDE) should be open.
Code
See Also
String object - Your Reference for String objects
CharacterAnalysis - We use the operators that allow us to recognise the type of character we are dealing with.
StringAdditionOperator - Add strings together in a variety of ways.
StringCaseChanges - Change the case of a string.
StringCharacters - Get/set the value of a specific character in a string.
StringComparisonOperators - Get/set the value of a specific character in a string.
StringConstructors - Initialize string objects.
StringIndexOf - Look for the first/last instance of a character in a string.
StringLength - Get the length of a string.
StringLengthTrim - Get and trim the length of a string.
StringReplace - Replace individual characters in a string.
StringStartsWithEndsWith - Check which characters/substrings a given string starts or ends with.
StringSubstring - Look for "phrases" within a given string.
StringToInt - Allows you to convert a String to an integer number.
Last revision 2015/08/11 by SM