Mega Code Archive

 
Categories / C# / Internationalization
 

Converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters

using System; using System.Text; class UTF8EncodingExample {     public static void Main() {         Char[] chars;         Byte[] bytes = new Byte[] {67, 68, 69, 70, 71, 72};         Decoder utf8Decoder = Encoding.UTF8.GetDecoder();         int charCount = utf8Decoder.GetCharCount(bytes, 0, bytes.Length);         chars = new Char[charCount];         int charsDecodedCount = utf8Decoder.GetChars(bytes, 0, bytes.Length, chars, 0);         Console.WriteLine(charsDecodedCount);         foreach (Char c in chars) {             Console.Write("[{0}]", c);         }     } }