Vadim's Weblog

Never stop learning.

Watch out for escape characters.

Posted by Vadim on September 22, 2007

You have to be aware of the escape characters when you parse a file  character by character.  For instance if you try to read a file that contains “C:\bigFile.txt” you’ll get back “C:igFile.txt” or something like this.

If you don’t believe me, try it yourselves.

   1: public void ParseString()
   2: {
   3:     string text = "C:\bigFile.txt";
   4:     string newText = string.Empty;
   5:     foreach (char c in text)
   6:     {
   7:         newText += c;
   8:     }
   9:     Console.WriteLine(newText);
  10: }

Below I provided a table of escape character for you and myself to reference later.

Char ASCII Dec# ASCII Hex# ASCII Name Ctrl Char Description
00 00 NUL ^@ null
\a 07 07 BEL ^G Alert
\b 08 08 BS ^H Backspace
\f 12 0C FF ^L Form feed
\n 10 0A LF ^J New line
\r 13 0D CR ^M Carriage return
\t 09 09 HT ^I Horizontal tab
\v 11 0B VT ^K Vertical tab
\” 34 22 N/A N/A Double quote
\’ 39 27 N/A N/A Single quote
\\ 92 5C NA N/A Backslash
\u#### N/A N/A N/A N/A Unicode escape
\x## N/A N/A N/A N/A Unicode escape
\Uxxxxxx N/A N/A N/A N/A Unicode escape

Let me know if I miss anything.

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: