C# UnicodeEncoding GetDecoder
Description
UnicodeEncoding GetDecoder
Obtains a decoder that converts
a UTF-16 encoded sequence of bytes into a sequence of Unicode characters.
Syntax
UnicodeEncoding.GetDecoder
has the following syntax.
public override Decoder GetDecoder()
Returns
UnicodeEncoding.GetDecoder
method returns A Decoder that converts a UTF-16 encoded sequence of bytes into a sequence
of Unicode characters.
Example
using System;/*from www . ja v a 2 s. co m*/
using System.Text;
public class SamplesUnicodeEncoding {
public static void Main() {
UnicodeEncoding u16 = new UnicodeEncoding( false, true, true );
Encoder myEnc = u16.GetEncoder();
Decoder myDec = u16.GetDecoder();
char[] myChars = new char[5] { 'z', 'a', 'd','e','f'};
int iBC = myEnc.GetByteCount( myChars, 0, myChars.Length, true );
byte[] myBytes = new byte[iBC];
myEnc.GetBytes( myChars, 0, myChars.Length, myBytes, 0, true );
Console.Write( "Using the encoder : " );
for ( int i = 0; i < myBytes.Length; i++ )
Console.Write( "{0:X2} ", myBytes[i] );
int iCC = myDec.GetCharCount( myBytes, 0, myBytes.Length, true );
char[] myDecodedChars = new char[iCC];
myDec.GetChars( myBytes, 0, myBytes.Length, myDecodedChars, 0, true );
Console.WriteLine( myDecodedChars );
}
}
The code above generates the following result.