article

C# - Asc and Chr functions

Email
Submitted on: 1/2/2015 10:43:00 AM
By: Özgür Aytekin (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C#
Views: 2212
 
     C# - Asc and Chr functions

 
				

www.dotnetcracks.com

 

C# - Asc and Chr functions

 

using System;

 

namespace ConsoleApplication2

{

      class Class1

      {

            [STAThread]

            static void Main(string[] args)

            {

                  Console.WriteLine("ASCII Code for A is           :" + Asc("A"));

                  Console.WriteLine("Character for ASCII Code 65 is:" + Chr(65).ToString());

 

                  Console.ReadLine();

            }

 

            private static int Asc(string character)

            {

                  if (character.Length == 1)

                  {

                        System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();

                       

                        int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];

 

                        return (intAsciiCode);

                  }

                  else

                  {

                        throw new ApplicationException("Character is not valid.");

                  }

            }

 

            private static string Chr(int asciiCode)

            {

                  if (asciiCode >= 0 && asciiCode <= 255)

                  {

                        System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();

                       

                        byte[] byteArray = new byte[]{(byte)asciiCode};

                        string strCharacter = asciiEncoding.GetString(byteArray);

 

                        return (strCharacter);

                  }

                  else

                  {

                        throw new ApplicationException("ASCII Code is not valid.");

                  }

            }

      }

}

 

 

Özgür Aytekin (MCSD .NET, MCDBA)

oezguer.aytekin at dotnetcracks dot com


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.