How do I escape ” in verbatim string? [duplicate]

Use a double quote:

 string s2 = @"This is \t a ""verbatim"" string";

With C# 11 you could also use a raw string literal, for example:

string longMessage = """
    This is a long message.
    It has several lines.
        Some are indented
                more than others.
    Some should start at the first column.
    Some have "quoted text" in them.
    """;

Raw string literals are a new format for string literals. Raw string literals can contain arbitrary text, including whitespace, new lines, embedded quotes, and other special characters without requiring escape sequences. A raw string literal starts with at least three double-quote (“””) characters. It ends with the same number of double-quote characters.

Leave a Comment

error code: 521