.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

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:\Program Files\My Program";        //verbatim literal

    string path2 = "C:\\Program Files\\My Program";      //regular literal

 

    string msg = @"Hello,

            This is a multi-line string";                //verbatim literal

 

    string msg2 = "Hello,\nThis is multi-line string";   //regular literal

P.S. the only character that requires a different action is the quotation mark itself, which must be entered twice to indicate a single character.

10/17/2007

Comments:

Name
URL
E-mail
Provide your e-mail address to receive notification about new comments.
Message
HTML tags are not supported.
Please add 7 and 1 and type the answer here:
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.