C#idiomatic C#
raw-stringcsharp/language-reference/tokens

Language

Raw string literal text - `"""` in string literals

Raw string literals can contain any arbitrary text without the need for special escape sequences. You begin and end a raw string literal with a minimum of three double-quote characters.

  • page csharp/language-reference/tokens/raw-string
  • updated 01/30/2026

A raw string literal starts and ends with a minimum of three double quote (") characters:

sample · csharpdocs/csharp/language-reference/tokens/snippets/raw-string-literal.csSingleLine

csharp

using System;

public static class RawStrings
{
    internal static void Examples()
    {
        // <SingleLine>
        var singleLine = """This is a "raw string literal". It can contain characters like \, ' and ".""";
        // </SingleLine>
        Console.WriteLine(singleLine);

        // <MultiLine>
        var xml = """
                <element attr="content">
                    <body>
                    </body>
                </element>
                """;
        // </MultiLine>
        Console.WriteLine(xml);

        // <MoarQuotes>
        var moreQuotes = """" As you can see,"""Raw string literals""" can start and end with more than three double-quotes when needed."""";
        // </MoarQuotes>
        Console.WriteLine(moreQuotes);

        // <InitialQuotes>
        var MultiLineQuotes = """"
                       """Raw string literals""" can start and end with more than three double-quotes when needed.
                       """";
        // </InitialQuotes>
        Console.WriteLine(MultiLineQuotes);
    }
}

Raw string literals can span multiple lines:

sample · csharpdocs/csharp/language-reference/tokens/snippets/raw-string-literal.csMultiLine

csharp

using System;

public static class RawStrings
{
    internal static void Examples()
    {
        // <SingleLine>
        var singleLine = """This is a "raw string literal". It can contain characters like \, ' and ".""";
        // </SingleLine>
        Console.WriteLine(singleLine);

        // <MultiLine>
        var xml = """
                <element attr="content">
                    <body>
                    </body>
                </element>
                """;
        // </MultiLine>
        Console.WriteLine(xml);

        // <MoarQuotes>
        var moreQuotes = """" As you can see,"""Raw string literals""" can start and end with more than three double-quotes when needed."""";
        // </MoarQuotes>
        Console.WriteLine(moreQuotes);

        // <InitialQuotes>
        var MultiLineQuotes = """"
                       """Raw string literals""" can start and end with more than three double-quotes when needed.
                       """";
        // </InitialQuotes>
        Console.WriteLine(MultiLineQuotes);
    }
}

ms.custom: "updateeachrelease"

The C# language reference documents the most recently released version of the C# language. It also contains initial documentation for features in public previews for the upcoming language release.

The documentation identifies any feature first introduced in the last three versions of the language or in current public previews.

The following rules govern the interpretation of a multiline raw string literal:

  • The opening quotes must be the last non-whitespace characters on their line, and the closing quotes must be the first non-whitespace characters on their line.
  • Any whitespace to the left of the closing quotes is removed from all lines of the raw string literal.
  • Any whitespace following the opening quotes on the same line is ignored.
  • Whitespace-only lines following the opening quote are included in the string literal.
  • The newline before the closing quotes isn't included in the literal string.
  • When whitespace precedes the end delimiter on the same line, the exact number and kind of whitespace characters (for example, spaces vs. tabs) must exist at the beginning of each content line. Specifically, a space doesn't match a horizontal tab, and vice versa.

The last rule is easy if you're consistent in how you use tabs (U+0009) or spaces (U+0020) for indenting your code, including raw string literals. You can use either, but don't mix them in the same multiline raw string literal. For example, the following declarations are legal (whitespace is drawn as \b for a space character and \t for a tab character:)

csharp
// Using `\b` and `\t` to visual the actual whitespace characters
var xml = """
\b\b\b\b<element attr="content">
\b\b\b\b\b\b<body>
\b\b\b\b\b\b</body>
\b\b\b\b</element>
\b\b\b\b""";

// Using `\b` and `\t` to visual the actual whitespace characters
var xmlTabs = """
\t\t\t\t<element attr="content">
\t\t\t\t\t\t<body>
\t\t\t\t\t\t</body>
\t\t\t\t</element>
\t\t\t\t""";

However, because the following declaration doesn't use a consistent format for the whitespace to the left of the closing """, the declaration is invalid:

csharp
// Using `\b` and `\t` to visual the actual whitespace characters
var xml = """
\t\b\b\b<element attr="content">
\b\t\b\b\b\b<body>
\b\b\t\b\b\b</body>
\b\b\b\t</element>
\b\b\b\b""";

author: BillWagner ms.author: wiwagn ms.topic: include ms.date: 10/07/2025

You might need to create a raw string literal that has three or more consecutive double-quote characters. Raw string literals can start and end with a sequence of at least three double-quote characters. When your string literal contains three consecutive double-quotes, you start and end the raw string literal with four double quote characters:

sample · csharpdocs/csharp/language-reference/tokens/snippets/raw-string-literal.csMoarQuotes

csharp

using System;

public static class RawStrings
{
    internal static void Examples()
    {
        // <SingleLine>
        var singleLine = """This is a "raw string literal". It can contain characters like \, ' and ".""";
        // </SingleLine>
        Console.WriteLine(singleLine);

        // <MultiLine>
        var xml = """
                <element attr="content">
                    <body>
                    </body>
                </element>
                """;
        // </MultiLine>
        Console.WriteLine(xml);

        // <MoarQuotes>
        var moreQuotes = """" As you can see,"""Raw string literals""" can start and end with more than three double-quotes when needed."""";
        // </MoarQuotes>
        Console.WriteLine(moreQuotes);

        // <InitialQuotes>
        var MultiLineQuotes = """"
                       """Raw string literals""" can start and end with more than three double-quotes when needed.
                       """";
        // </InitialQuotes>
        Console.WriteLine(MultiLineQuotes);
    }
}

If you need to start or end a raw string literal with quote characters, use the multiline format:

sample · csharpdocs/csharp/language-reference/tokens/snippets/raw-string-literal.csInitialQuotes

csharp

using System;

public static class RawStrings
{
    internal static void Examples()
    {
        // <SingleLine>
        var singleLine = """This is a "raw string literal". It can contain characters like \, ' and ".""";
        // </SingleLine>
        Console.WriteLine(singleLine);

        // <MultiLine>
        var xml = """
                <element attr="content">
                    <body>
                    </body>
                </element>
                """;
        // </MultiLine>
        Console.WriteLine(xml);

        // <MoarQuotes>
        var moreQuotes = """" As you can see,"""Raw string literals""" can start and end with more than three double-quotes when needed."""";
        // </MoarQuotes>
        Console.WriteLine(moreQuotes);

        // <InitialQuotes>
        var MultiLineQuotes = """"
                       """Raw string literals""" can start and end with more than three double-quotes when needed.
                       """";
        // </InitialQuotes>
        Console.WriteLine(MultiLineQuotes);
    }
}

Raw string literals can also be combined with interpolated strings to embed the { and } characters in the output string. You use multiple $ characters in an interpolated raw string literal to embed { and } characters in the output string without escaping them.

The raw string literal's content must not contain a set of contiguous " characters whose length is equal to or greater than the raw string literal delimiter length. For example, the strings """" """ """" and """"""" """""" """"" """" """ """"""" are well-formed. However, the strings """ """ """ and """ """" """ aren't well-formed.

See also