Mega Code Archive

 
Categories / C# Tutorial / Internationalization
 

Encode a range of elements from a Unicode character array and store the encoded bytes in a range of elements in a byt

using System; using System.Text; class UnicodeEncodingExample {     public static void Main() {         Byte[] bytes;         Char[] chars = new Char[] {             '\u0023', // #             '\u0025', // %             '\u03a0', // Pi             '\u03a3'  // Sigma         };         UnicodeEncoding Unicode = new UnicodeEncoding();         int byteCount = Unicode.GetByteCount(chars, 1, 2);         bytes = new Byte[byteCount];         int bytesEncodedCount = Unicode.GetBytes(chars, 1, 2, bytes, 0);         Console.WriteLine(bytesEncodedCount);         foreach (Byte b in bytes) {             Console.WriteLine(b);         }     } }