typestar

String interpolation in Dart

Templates with $, expression braces, and multiline literals.

void main() {
  const bird = 'goldfinch';
  const count = 7;
  // $name splices a value; ${...} splices any expression.
  print('$count $bird sightings');
  print('Even flock? ${count.isEven}');

  // Adjacent literals concatenate; triple quotes span lines.
  const banner = 'MORNING '
      'WATCH';
  const sign = '''
Hide rules:
  quiet voices, $bird nesting''';
  print('$banner\n$sign');
}

How it works

  1. $count drops a value in; ${count.isEven} runs any expression.
  2. Adjacent string literals concatenate across lines.
  3. Triple quotes span lines and still interpolate.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
368
Tokens
75
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 64 seconds.

Type this snippet

Step 3 of 3 in Values, step 3 of 27 in Language basics.

← Previous Next →

String interpolation in other languages