Aleksandar's computer workshop

Let's see what Aleksandar was fixing today.
My findings, tips & tricks related to computers, internet, programming and other stuff I was working with.

Verbatim string literals

Verbatim string literal does not require the use of escape characters to define special characters. Instead, any information in the source code, including new lines, is included in the string. To define a string literal an @ symbol is placed before the opening quotation mark. Verbatim string literals are often used for specifying paths and multi-line strings:

    string path = @"C:\Data\File.ext"; //verbatim literal

    string path = "C:\\Data\\File.ext"; //regular literal

    string msg = @"First line,
                           Second line"; //verbatim literal

    string msg = "First line,\nSecond line"; //regular literal

    string quote = "This is \"quote\" sample"; //regular literal

    string quote = @"This is ""quote"" sample"; //regular literal

In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals.

More details:

C# String literals

Comments are closed