Advertisement
Guest User

PrintTheASCIITable

a guest
Mar 15th, 2014
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace PrintTheASCIITable
  5. {
  6.     class PrintTheASCIITable
  7.     {
  8.         static void Main()
  9.         {
  10.             Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.             for (byte index = 0; index < byte.MaxValue; index++)
  13.             {
  14.                 byte[] byteArray = { index };
  15.                 char[] asciiArray = Encoding.GetEncoding(437).GetChars(byteArray);
  16.                 char asciiSign = asciiArray[0];
  17.                 //or: char asciiSign = Encoding.GetEncoding(437).GetChars(new byte[]{index})[0];
  18.                
  19.                 switch (index)
  20.                 {
  21.                     case 0:   Console.WriteLine("{0} = not visible (null)", index); break;
  22.                     case 7:   Console.WriteLine(@"{0} = not visible (""beep!"" sound)", index); break;
  23.                     case 8:   Console.WriteLine("{0} = not visible (backspace)", index); break;
  24.                     case 9:   Console.WriteLine("{0} = not visible (horizontal tab)", index); break;
  25.                     case 10:  Console.WriteLine("{0} = not visible (new line)", index); break;
  26.                     case 13: Console.WriteLine("{0} = not visible (carriage return)", index); break;
  27.                     case 127: Console.WriteLine("{0} = not visible (DEL)", index); break;
  28.                     case 32: Console.WriteLine("{0} = space", index); break;
  29.              
  30.                     default: Console.WriteLine("{0} = {1}", index, asciiSign); break;
  31.                 }              
  32.             }
  33.             char lastChar = Encoding.GetEncoding(437).GetChars(new byte[] { 255 })[0];
  34.             Console.WriteLine("{0} = not visible", 255, lastChar);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement