Unicode Encoding Example : Unicode « I18N Internationalization « C# / CSharp Tutorial






using System;
using System.Text;

class MainClass {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0};

        UnicodeEncoding Unicode = new UnicodeEncoding();

        int charCount = Unicode.GetCharCount(bytes, 2, 8);
        chars = new Char[charCount];
        int charsDecodedCount = Unicode.GetChars(bytes, 2, 8, chars, 0);

        Console.WriteLine(charsDecodedCount);

        foreach (Char c in chars) {
            Console.WriteLine("[{0}]", c);
        }
    }
}








21.15.Unicode
21.15.1.Create and write a string containing the symbol for Pi
21.15.2.Use GetByteCount to return the number of bytes required to encode an array of Unicode characters, using UTF8Encoding.
21.15.3.Unicode Encoding Example
21.15.4.Decode a range of elements from a byte array and store them in a Unicode character array
21.15.5.Unicode Encoding Example
21.15.6.List the Unicode code point of each of the control characters.
21.15.7.Encode a range of elements from a Unicode character array and store the encoded bytes in a range of elements in a byte array.