Share via


What character escape sequences are available?

C# defines the following character escape sequences:

  • \' - single quote, needed for character literals
  • \" - double quote, needed for string literals
  • \\ - backslash
  • \0 - Unicode character 0
  • \a - Alert (character 7)
  • \b - Backspace (character 8)
  • \f - Form feed (character 12)
  • \n - New line (character 10)
  • \r - Carriage return (character 13)
  • \t - Horizontal tab (character 9)
  • \v - Vertical quote (character 11)
  • \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)

Of these, \a, \f, \v, \x and \U are rarely used in my experience.

[Author: Jon Skeet]

Comments

  • Anonymous
    March 13, 2004
    The comment has been removed

  • Anonymous
    April 19, 2004
    thank you

  • Anonymous
    April 19, 2004
    good

  • Anonymous
    July 30, 2007
    The comment has been removed

  • Anonymous
    January 18, 2009
    PingBack from http://www.keyongtech.com/2771764-path

  • Anonymous
    March 10, 2010
    The comment has been removed

  • Anonymous
    March 20, 2010
    axwfoss: I don't know how it is in WinForms/C#, but in Win32/Delphi a number of GUI elements(such as as labels and menus) use & to mark an accelerator. The & is not displayed then, but instead the following char is underlined.

  • Anonymous
    March 31, 2010
    v is called 'vertical tab' not 'vertical quote'

  • Anonymous
    August 30, 2010
    This is cool stuff!!!!

  • Anonymous
    November 30, 2010
    I'm new to c# and this will come in handy.  THANKS BOB! ;-] .... my windows phone prof. for those who are wondering who Bob is.

  • Anonymous
    February 23, 2011
    One thing I'm confused about: the double backslash \ is the escape sequence for a backslash, making it useful for specifying file paths, but I just encountered a program that used a double slash // in the filename string literal.  It seems to me that this should not work, but it does.  Why?

  • Anonymous
    August 31, 2011
    what is the use of escape character r in programing?

  • Anonymous
    August 31, 2011
    what is the use of escape character r in programing?

  • Anonymous
    August 31, 2011
    what is the use of escape character r in programing?

  • Anonymous
    September 09, 2011
    sir,how to use b in c file???????????pl reply me mail-ramswarooppatra@gmail.com

  • Anonymous
    September 14, 2011
    handling single quotes net-informations.com/.../single-quotes.htm gev

  • Anonymous
    January 27, 2012
    how to represent  single quotation [  '  ] in char data type ?

  • Anonymous
    April 25, 2013
    Can the horizontal tab width be modified? EX: make it 1 space instead of 4...

  • Anonymous
    November 04, 2015
    Hi , can anyone explain what is the purpose of r ? Thank you