C# ASCII Character Codes

Created by
Wednesday, August 3, 2016

Today we are going to write a program in C# that accepts a character and determines using if statements whether or not it is an upper case letter, a lower case letter, a number or a special character. Put simply ASCII stands for the American Code for Information Interchange. It is a code that represents characters as numbers which in essence is the way in which a machine understands them, Each character uses 7 bits.

Using the table below you can see how the code works. What to test yourself with another small challenge? Build the code out in a better manner to also take into consideration extended ASCII shown here.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("www.dotnetdevelopernetwork.com");

        char a;
        int b;

        Console.WriteLine("Enter Charachter: ");
        Char.TryParse(Console.ReadLine(), out a);

        b = (int)a;

        if ( b >= 65 && b <= 90 )
        {
            Console.WriteLine("Entry is a Upper Case Letter.");
        }

        if ( b >= 97 && b <= 122 )
        {
            Console.WriteLine("Entry is a Lower Case Letter.");
        }

        if ( b >= 48 && b <= 57 )
        {
            Console.WriteLine("Entry is a Digit.");
        }

        if ( b == 0 && b <= 47 || b >= 58 && b <= 64 || b >= 91 && b <= 96 || b >= 123 && b <= 127 )
        {
            Console.WriteLine("Entry is a special Charachter");
        }

        Console.ReadKey();
    }
}
Tags:
c#
ascii
codes
0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments