Working with Text
7 min · Dart
Join strings, measure them, and use string interpolation.
Enemy 1 of 5
Concatenation with +
Dart lets you join two strings together with the + operator — the same symbol you use for adding numbers, but Dart determines from the types involved that this means "stick these two pieces of text together" rather than "add these numbers." Like most languages' concatenation operators, + doesn't add a space automatically, so if you want a gap between the joined pieces you need to include it yourself (notice greeting already ends with a trailing space in the example).
Dart accepts both single quotes and double quotes for strings, and unlike Ruby or PHP, there's no behavioral difference between them (no separate "interpolating" vs. "literal" quote style) — pick whichever is more convenient for the string you're writing, for example switching to double quotes if the text itself contains an apostrophe.
Loading editor...