c string encodings encodings of encoding use method example

  • 2020-05-27 06:56:17
  • OfStack

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";
            // 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(" Decoded string: ");
            // The following statement will be correct encodeBytes The contents of the byte array are decoded 
            string decodeStr = myAscii.GetString(encodeBytes);

Related articles: