C# Escape Sequence Listing

String Operations

What is an escape sequence? Well, put simply, an escape sequence is a series of special characters which are interpreted by the compiler as a command. In other words, they suspend the normal processing to perform some special function.

In C#, escape sequences are represented by a ‘\’ (backslash) followed by a letter or a combination of digits.

The following table represents the most common escape sequences used in C#.

Escape Sequence What it Represents
\’ Single Quotation Mark (character 39)
\” Double Quotation Mark (character 34)
\? Literal Question Mark
\\ Backslash (character 92)
\a Alert/Bell (character 7)
\b Backspace (character 8 )
\f Formfeed (character 12)
\n New Line (character 10)
\r Carriage Return (character 13)
\t Horizontal Tab (character 9)
\v Vertical Tab (character 11)
\ooo ASCII character in octal notation
\xhh ASCII character in hexadecimal notation


  1. In the below code we are escaping the backslash in the path string.

    string path = "C:\\Program Files\\Microsoft";

    The result would look like this: C:\Program Files\Microsoft

  2. In the below code we are adding a carriage return and a new line by using the \r\n escape sequences together.

    MessageBox.Show("Hello from...\r\nhttp://www.daveoncsharp.com", 
                    "Escape Sequences", 

    The result will be a message box with the message string split on two lines as shown below.


I hope you found this useful. Feel free to visit this blog often for more similar articles.


DaveOnCSharp.com runs on the Thesis Theme

How smart is your Theme? How good is your support? Check out ThesisTheme for WordPress.

The Thesis Theme is one of the best Wordpress frameworks out there, especially if you understand software development, which since you're here you probably do. Thesis allows you to design post and page templates using a drag-and-drop system which gives you access to all the relevant page elements you would normally have to manually access through code. This is why understanding development techniques definitely helps, even though you don't need to write any code to get Thesis up and running.

So go check out the incredible features at DIYThemes and start using Thesis now!

7 comments… add one
  • Good article. I believe you left out \u and \U, however.

    \uxxxx – Unicode escape sequence for character with hex value xxxx
    \xn[n][n][n] – Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
    \Uxxxxxxxx – Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

    • Yes Chad, you are right. Thanks for pointing that out 🙂

  • Omid

    Hello! David.

    I think your blog is very simple to use for every body all over the world!

    😉 thanks my friend.

    I live in kish island in south of iran. I’m an employee of airport.

    • You’re welcome. Thanks for the comment.

  • Ali

    hi thanks in advance.. can you please help me in this situation, actually i have function which return string, i want this string with escape sequences.. because i want them on other page. because processing of that string will be done on another page. can you help me in this? how we can accomplish this?

  • Very useful!
    As many other articles in this blog!
    Thank you!

  • isn’t working with listbox. Please help me.

    listBox1.Items.Add(textBox1.Text + ” Giriş Saati\r\n” + DateTime.Now.Hour+”:”+DateTime.Now.Minute);

Leave a Comment