C# Encoding ASCII

Description

Encoding ASCII Gets an encoding for the ASCII (7-bit) character set.

Syntax

Encoding.ASCII has the following syntax.


public static Encoding ASCII { get; }

Example


using System;/*from w ww  .  ja va 2 s .  c o m*/
using System.Text;

public class Example
{
   public static void Main()
   {
      Encoding enc = Encoding.GetEncoding("us-ascii", 
                                          new EncoderExceptionFallback(),
                                          new DecoderExceptionFallback());
      string value = "\u00C4 \u00F6 \u00AE"; 

       byte[] bytes= enc.GetBytes(value);
       foreach (var byt in bytes)
          Console.Write("{0:X2} ", byt);
       Console.WriteLine();

       string value2 = enc.GetString(bytes);
       Console.WriteLine(value2);

      Encoding ascii = Encoding.ASCII;

      String unicodeString =
          "Pi (\u03a0) and Sigma (\u03a3).";
      Byte[] encodedBytes = ascii.GetBytes(unicodeString);
      foreach (Byte b in encodedBytes) 
      {
          Console.Write("[{0}]", b);
      }
      Console.WriteLine();
      String decodedString = ascii.GetString(encodedBytes);
      Console.WriteLine();
      Console.WriteLine(decodedString);
  }
}




















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding