C# Frequently Asked Questions

The C# team posts answers to common questions

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]

Published Friday, March 12, 2004 12:15 AM by CSharpFAQ

Comments

 

Avner Kashtan said:

Just for the anecdotal value:
\v is very useful when doing Word automation to generate documents programmatically. Pushing a \v into the doc is equivalent to pressing Shift-Enter in Word itself - it does a line break that doesn't end the paragraph, thus not triggering the auto-numbering or auto-bulleting, as well as many other potentially undesirable effects in the sticky morass of unexpected side-effects that is automating Word. :)
March 13, 2004 11:22 PM
 

Chris Burrows .NET Blog said:

March 16, 2004 5:10 AM
 

Forest Blog said:

April 6, 2004 4:32 AM
 

英国留学 said:

thank you
April 19, 2004 7:46 PM
 

fda注册 said:

good
April 19, 2004 7:47 PM
 

Design & Development Blog said:

C# Character Escape Sequences' - single quote, needed for character literals" - double quote, needed for string literals\ - backslash0 - Unicode character 0a - Alert (character 7)b - Backspace (character f - Form feed (character 12)n - New line (charac

July 30, 2007 10:16 AM
 

Path | keyongtech said:

January 18, 2009 11:51 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker