Raw String Literals
Write multiline and quote-heavy text cleanly.
Raw String Literals is a free C# Academy lesson on CoddyKit — lesson 4 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 C# Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Raw String Literals
A raw string literal is wrapped in at least three double quotes. Inside, characters are taken literally, with no escape processing.
using System;
class Program {
static void Main() {
string s = """Hello "World"!""";
Console.WriteLine(s);
}
}No Escape Sequences
Backslashes are plain backslashes inside a raw string, which is perfect for file paths and regex patterns.
using System;
class Program {
static void Main() {
string path = """C:\Users\Ada\file.txt""";
Console.WriteLine(path);
}
}Embedding Quotes
Because the delimiter is three or more quotes, single and double quotes inside need no escaping.
using System;
class Program {
static void Main() {
string json = """{"name": "Ada", "age": 30}""";
Console.WriteLine(json);
}
}Multi-Line Raw Strings
For multi-line content, put the opening and closing quotes on their own lines. The text between them is preserved.
using System;
class Program {
static void Main() {
string text = """
Line one
Line two
""";
Console.WriteLine(text);
}
}Indentation Is Stripped
In multi-line raw strings, the whitespace before the closing quotes sets the baseline indent, which is removed from every line.
using System;
class Program {
static void Main() {
string s = """
indented in source
but flush in output
""";
Console.WriteLine(s);
}
}More Quotes for Conflicts
If your content contains three quotes, use four or more in the delimiter so the string is unambiguous.
using System;
class Program {
static void Main() {
string s = """"He said """quote""" today."""";
Console.WriteLine(s);
}
}Raw Interpolation
Prefix with a dollar sign for interpolated raw strings. The number of dollar signs sets how many braces start an expression.
using System;
class Program {
static void Main() {
string name = "Ada";
string s = $"""Hello, {name}!""";
Console.WriteLine(s);
}
}Double Dollar for Literal Braces
With two dollar signs, single braces are literal and double braces start an expression, handy for JSON templates.
using System;
class Program {
static void Main() {
string id = "42";
string s = $$"""{ "id": {{id}} }""";
Console.WriteLine(s);
}
}Cleaner Than Verbatim
Raw strings replace many uses of the older verbatim form, with clearer handling of quotes and indentation.
using System;
class Program {
static void Main() {
string sql = """
SELECT *
FROM Users
WHERE Active = 1
""";
Console.WriteLine(sql);
}
}Great for Templates
Raw strings make embedding JSON, XML, HTML, or SQL readable because nothing inside needs escaping.
using System;
class Program {
static void Main() {
string html = """<a href="/home">Home</a>""";
Console.WriteLine(html);
}
}When to Use Them
Reach for raw strings whenever your text has many quotes, backslashes, or spans multiple lines.
using System;
class Program {
static void Main() {
string regex = """\d{3}-\d{4}""";
Console.WriteLine(regex);
}
}Quick Check
Test your understanding of raw string literals.
Recap
Raw string literals use three or more double quotes and take their content literally, with no escape sequences, which is ideal for paths, regex, JSON, and HTML. Multi-line versions preserve layout and strip the closing-quote indentation.
Add more quotes when content conflicts, and prefix with dollar signs for interpolation, where extra dollar signs change how braces are interpreted.
Frequently asked questions
Is the “Raw String Literals” lesson free?
Yes — the full text of “Raw String Literals” is free to read here on the web, and the C# 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 C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “Raw String Literals”?
Write multiline and quote-heavy text cleanly. You practise C# 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 C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Raw String Literals” 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 C# Academy lesson?
Yes. Every C# 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.