Escape Sequences

Escape characters are part of the syntax for many programming languages, data formats and communication protocols. For a given alphabet an escape character’s purpose is to start character sequences (so named escape sequences) which have to be interpreted differently from the same characters occurring alone. An escape character may not have its own meaning, so all escape sequences are of 2 or more characters.

Example:

If I run this little application I get this result:

So by using two characters (\n) I can get my message displayed in two lines.

The most interesting character is the backslash itself.

This gives me the following error message:

Apparently the backslash is just recognized when followed by a second backslash.

The C# compiler recognizes the following character escape sequences:

\ ‘       single quote, needed for character literals

\ ”      double quote, needed for string literals

\ \      backslash

\ 0      Null

\ a      Alert

\ b     Backspace

\ f      Form feed

\ n      New line

\ r       Carriage return

\ t       Horizontal tab

\ v       Vertical quote

\ u       Unicode escape sequence for character

\ U      Unicode escape sequence for surrogate pairs.

\ x       Unicode escape sequence similar to “\u” except with variable length.

 

To be continued…

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: