Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

How to generates the ASCII table (0-127) in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Decimal".PadRight(9));
            Console.Write("ASCII".PadRight(9));
            Console.Write("Hex".PadRight(9));
            Console.WriteLine();

            int min = 0;
            int max = 128;
            for (int i = min; i < max; i++)
            {
                char ch = (char)i;

                string s = string.Empty;
                if (char.IsWhiteSpace(ch))
                {
                    s = ch.ToString();
                    switch (ch)
                    {

                        case ' ':
                            s = "space";
                            break;
                        case '\n':
                            s = "\\n";
                            break;
                        case '\r':
                            s = "\\r";
                            break;
                        case '\t':
                            s = "\\t";
                            break;
                        case '\f':
                            s = "\\f";
                            break;
                        case '\v':
                            s = "\\v";
                            break;
                    }
                }
                else if (char.IsControl(ch))
                    s = "ctrl ch";
                else
                    s = ch.ToString();

                Console.Write(i.ToString().PadRight(9));
                Console.Write(s.PadRight(9));
                Console.Write(i.ToString("X2"));
                Console.WriteLine();
            }
        }
    }
}


/*
run:
 
Decimal  Char    Hex
0        ctrl ch  00
1        ctrl ch  01
2        ctrl ch  02
3        ctrl ch  03
4        ctrl ch  04
5        ctrl ch  05
6        ctrl ch  06
7        ctrl ch  07
8        ctrl ch  08
9        \t       09
10       \n       0A
11       \v       0B
12       \f       0C
13       \r       0D
14       ctrl ch  0E
15       ctrl ch  0F
16       ctrl ch  10
17       ctrl ch  11
18       ctrl ch  12
19       ctrl ch  13
20       ctrl ch  14
21       ctrl ch  15
22       ctrl ch  16
23       ctrl ch  17
24       ctrl ch  18
25       ctrl ch  19
26       ctrl ch  1A
27       ctrl ch  1B
28       ctrl ch  1C
29       ctrl ch  1D
30       ctrl ch  1E
31       ctrl ch  1F
32       space    20
33       !        21
34       "        22
35       #        23
36       $        24
37       %        25
38       &        26
39       '        27
40       (        28
41       )        29
42       *        2A
43       +        2B
44       ,        2C
45       -        2D
46       .        2E
47       /        2F
48       0        30
49       1        31
50       2        32
51       3        33
52       4        34
53       5        35
54       6        36
55       7        37
56       8        38
57       9        39
58       :        3A
59       ;        3B
60       <        3C
61       =        3D
62       >        3E
63       ?        3F
64       @        40
65       A        41
66       B        42
67       C        43
68       D        44
69       E        45
70       F        46
71       G        47
72       H        48
73       I        49
74       J        4A
75       K        4B
76       L        4C
77       M        4D
78       N        4E
79       O        4F
80       P        50
81       Q        51
82       R        52
83       S        53
84       T        54
85       U        55
86       V        56
87       W        57
88       X        58
89       Y        59
90       Z        5A
91       [        5B
92       \        5C
93       ]        5D
94       ^        5E
95       _        5F
96       `        60
97       a        61
98       b        62
99       c        63
100      d        64
101      e        65
102      f        66
103      g        67
104      h        68
105      i        69
106      j        6A
107      k        6B
108      l        6C
109      m        6D
110      n        6E
111      o        6F
112      p        70
113      q        71
114      r        72
115      s        73
116      t        74
117      u        75
118      v        76
119      w        77
120      x        78
121      y        79
122      z        7A
123      {        7B
124      |        7C
125      }        7D
126      ~        7E
127      ctrl ch  7F

*/

 



answered Mar 13, 2017 by avibootz
...