Multi-line and Raw Strings
Handle newlines and escape-free text.
Multi-line and Raw Strings is a free Dart Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Newline Problem
Sometimes text needs to span several lines, like a poem or an address. Dart gives you two clean ways to handle this.
Triple Quotes for Many Lines
Triple quotes let you press Enter inside a string. Every line break you type becomes a real newline in the text.
var addr = '''123 Main St
Apt 4''';Both Quote Styles Triple
Triple quotes come in both flavors: three single quotes or three double quotes. They behave the same, so pick whichever fits your text.
var s = """line one
line two""";The Newline Escape
You can also insert a line break with the newline escape backslash-n. It is handy for single-quoted strings without going multi-line.
var s = 'top\nbottom';Watch That First Line
With triple quotes, text right after the opening marks starts immediately. A line break before your content adds a blank first line.
var s = '''
starts on line two''';Escapes Still Work
Inside normal strings, the backslash is special. It powers escapes like a tab, a newline, or a literal quote.
var s = 'col1\tcol2';Enter Raw Strings
A raw string turns off all escape processing. Prefix the string with the letter r and every backslash stays exactly as typed.
var path = r'C:\Users\Ada';Why Raw Helps
Raw strings shine for file paths and regular expressions, where backslashes are everywhere and escaping each one is painful.
var pattern = r'\d+';Raw Disables Interpolation Too
In a raw string the dollar sign is just a character. Interpolation is switched off, so $name appears literally rather than its value.
var s = r'cost is $price';Combine Raw and Triple
You can stack the features: a raw triple-quoted string spans many lines and keeps every backslash literal at once.
var s = r'''path\one
path\two''';Choose the Right Tool
Use triple quotes for multi-line text and raw for backslash-heavy text. Together they cover almost any tricky string.
Quick Check
You want a string where backslashes are kept literally. What do you use?
Recap: Big and Raw Strings
You learned that triple quotes handle multi-line text and a raw prefix keeps backslashes and dollar signs literal. 🎉
Frequently asked questions
Is the “Multi-line and Raw Strings” lesson free?
Yes — the full text of “Multi-line and Raw Strings” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Multi-line and Raw Strings”?
Handle newlines and escape-free text. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multi-line and Raw Strings” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- String Literals and Quotes
- String Interpolation With the Dollar Sign
- Multi-line and Raw Strings
- Everyday String Methods