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

Verbatim string literals

March 6, 2008 15:41 by Aleksandar

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


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Programming | Windows
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


 

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]