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.

circuit

Code

See Also

Last revision 2015/08/11 by SM