C# UTF8Encoding GetDecoder

Description

UTF8Encoding GetDecoder Obtains a decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters.

Syntax

UTF8Encoding.GetDecoder has the following syntax.


public override Decoder GetDecoder()

Returns

UTF8Encoding.GetDecoder method returns A Decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters.

Example

The following example demonstrates how to use the GetDecoder method to obtain a UTF-8 decoder.


/*from  w  w  w  .j  ava 2s. c o m*/

using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {99, 204, 128, 234, 130, 160};

        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.WriteLine("[{0}]", c);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding