Mega Code Archive

 
Categories / C# / Internationalization
 

Encodes a set of characters from the specified String into the specified byte array

using System; using System.Text; class UTF8EncodingExample {     public static void Main() {         Byte[] bytes;         Char[] chars = new Char[] { '\u03a3' };// Sigma         UTF8Encoding utf8 = new UTF8Encoding();         int byteCount = utf8.GetByteCount(chars, 1, 2);         bytes = new Byte[byteCount];         int bytesEncodedCount = utf8.GetBytes(chars, 1, 2, bytes, 0);         Console.WriteLine(bytesEncodedCount);         foreach (Byte b in bytes) {             Console.Write("[{0}]", b);         }     } }