Strings
Raw and Multiline Strings
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
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');
}
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>`.