Vadim's Weblog

Never stop learning.

Archive for September 22nd, 2007

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.

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.