Dart has two string forms that make awkward text easier to write. A raw string r'...' keeps every backslash literal, so a Windows-style path or a regex pattern reads as-is without doubled backslashes. A triple-quoted string '''...''' spans multiple source lines without explicit \n; each newline in the source becomes a real newline in the value. Once built, both forms work with the usual String methods like .contains and .split.

Program

Play the program to build a raw Windows-style path, build a triple-quoted two-line poem, then check the path, split the poem, and print a summary.

raw_multiline.dart
Replay: real traced execution (multi-file project)
void main() {
  var winPath = r'C:\Users\Ada\notes.txt';
  var hasUsers = winPath.contains(r'\Users\');
  var poem = '''line one
line two''';
  var lines = poem.split('\n');
  var count = lines.length;
  var joined = lines.join(' | ');
  print('$hasUsers $count $joined');
}
  1. winPath ← C:\Users\Ada\notes.txt

    1void main() {2  var winPath = r'C:\Users\Ada\notes.txt';3  var hasUsers = winPath.contains(r'\Users\');
    values this stepC:\Users\Ada\notes.txtwinPath
  2. hasUsers ← true

    2var winPath = r'C:\Users\Ada\notes.txt';3var hasUsers = winPath.contains(r'\Users\');4var poem = '''line one
    values this steptruehasUsersC:\Users\Ada\notes.txtwinPath
  3. poem ← line one\nline two

    3  var hasUsers = winPath.contains(r'\Users\');4  var poem = '''line one5line two''';
    values this stepline one\nline twopoem
  4. lines ← [line one, line two]

    5line two''';6  var lines = poem.split('\n');7  var count = lines.length;
    values this step[line one, line two]linesline one\nline twopoem
  5. count ← 2

    6var lines = poem.split('\n');7var count = lines.length;8var joined = lines.join(' | ');
    values this step2count[line one, line two]lines
  6. joined ← line one | line two

    7var count = lines.length;8var joined = lines.join(' | ');9print('$hasUsers $count $joined');
    values this stepline one | line twojoined[line one, line two]lines
  7. print('$hasUsers $count $joined');

    8  var joined = lines.join(' | ');9  print('$hasUsers $count $joined');10}
    outputtrue 2 line one | line two
    values this steptruehasUsers2countline one | line twojoined

Follow the Strings

  1. winPath is C:\Users\Ada\notes.txt.
  2. .contains(r'\Users\') makes hasUsers true.
  3. The poem splits into line one and line two.
  4. count becomes 2.
  5. Joining with | gives line one | line two, so the output is true 2 line one | line two. | value | result | | --- | --- | | path check | true | | split lines | line one, line two | | count | 2 | | joined | line one | line two |
raw strings `r'...'` keeps every backslash literal. A Windows path or regex pattern then reads exactly as written, with no need to double each `\`.
triple-quoted strings `'''...'''` spans multiple source lines; each newline in the source becomes a real newline in the value, so the string body reads like the original block.
methods are the same Whatever the literal form, the resulting `String` exposes the same methods: `.contains(needle)` returns a `bool`, `.split(sep)` returns a `List<String>`.

Exercise: raw_multiline.dart

Reproduce true 2 line one | line two, then trace how the raw path check, two split lines, and joined text build that output.