Advertisement
Guest User

pritASCIITable

a guest
Mar 11th, 2014
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2.  
  3. class PrintAsciiTable
  4. {
  5.     static void Main()
  6.     {
  7.         Console.OutputEncoding = System.Text.Encoding.Unicode;
  8.         Console.Write("Decimal".PadRight(10));
  9.         Console.Write("ASCII".PadRight(10));
  10.         Console.Write("Hex".PadRight(10));
  11.         Console.WriteLine();
  12.  
  13.         int min = 0;
  14.         int max = 127;
  15.         string lineSeparator;
  16.         for (int i = min; i < max; i++)
  17.         {
  18.             // Get ascii character.
  19.             char c = (char)i;
  20.  
  21.             // Get display string.
  22.             string display = string.Empty;
  23.             if (char.IsWhiteSpace(c))
  24.             {
  25.                 display = c.ToString();
  26.                 switch (c)
  27.                 {
  28.                     case '\t':
  29.                         display = "\\t";
  30.                         break;
  31.                     case ' ':
  32.                         display = "space";
  33.                         break;
  34.                     case '\n':
  35.                         display = "\\n";
  36.                         break;
  37.                     case '\r':
  38.                         display = "\\r";
  39.                         break;
  40.                     case '\v':
  41.                         display = "\\v";
  42.                         break;
  43.                     case '\f':
  44.                         display = "\\f";
  45.                         break;
  46.                 }
  47.             }
  48.             else if (char.IsControl(c))
  49.             {
  50.                 display = "control";
  51.             }
  52.             else
  53.             {
  54.                 display = c.ToString();
  55.             }
  56.             // Write table row.
  57.             Console.Write(i.ToString().PadRight(10));
  58.             Console.Write(display.PadRight(10));
  59.             Console.Write(i.ToString("X2"));
  60.             Console.WriteLine();
  61.         }
  62.         lineSeparator = new string('=', 10);
  63.         Console.WriteLine(lineSeparator);
  64.         Console.WriteLine("press any key to end.");
  65.         Console.ReadKey();
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement