c string encodings encodings of encoding use method example


Unicode comes in four encoding formats, UTF-8, UTF-16, UTF-32, UTF-7.

A character encoding, ASCIIEncoding, UTF7Encoding UnicodeEncoding, UTF32Encoding.

using System.Collections.Generic;
using System.Text;
namespace AsciiEncodingDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            ASCIIEncoding myAscii = new ASCIIEncoding();
            string unicodeStr = "ASCII Encoding Demo";
            Console.WriteLine(unicodeStr);
            // The following code will do the following unicodeStr The contents of the string are encoded.
            Byte[] encodeBytes = myAscii.GetBytes(unicodeStr);
            Console.WriteLine(" Encoded string: ");
            foreach (byte c in encodeBytes)
            {
                Console.Write("[{0}]", c);
            }
            Console.WriteLine("");
            Console.WriteLine(" Decoded string: ");
            // The following statement will be correct encodeBytes The contents of the byte array are decoded
            string decodeStr = myAscii.GetString(encodeBytes);
            Console.WriteLine(decodeStr);
            Console.ReadLine();        
         }
    }
}