String Appending Operators

Use the += operator and the concat() method to append things to Strings.

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:

1String stringOne = "A long integer: ";
2// using += to add a long variable to a string:
3stringOne += 123456789;

or

1String stringTwo = "A long integer: ";
2// using concat() to add a long variable to a string:
3stringTwo.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

Learn more

You can find more basic tutorials in the built-in examples section.

You can also explore the language reference, a detailed collection of the Arduino programming language.

Last revision 2015/08/11 by SM

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.