Encode a set of characters from the specified character array
using System; using System.Text; class EncoderExample { public static void Main() { Byte[] bytes; Char[] chars = new Char[] { '\u03a3' // Sigma }; Encoder uniEncoder = Encoding.Unicode.GetEncoder(); int byteCount = uniEncoder.GetByteCount(chars, 0, chars.Length, true); bytes = new Byte[byteCount]; int bytesEncodedCount = uniEncoder.GetBytes(chars, 0, chars.Length, bytes, 0, true); Console.WriteLine(bytesEncodedCount); foreach (Byte b in bytes) { Console.Write("[{0}]", b); } } }
1. | Encoder converts a set of characters into a sequence of bytes. | ||
2. | Create a new instance of the Encoder class | ||
3. | Calculates the number of bytes produced by encoding a set of characters |