C# UnicodeEncoding GetChars(Byte[], Int32, Int32, Char[], Int32)

Description

UnicodeEncoding GetChars(Byte[], Int32, Int32, Char[], Int32) Decodes a sequence of bytes from the specified byte array into the specified character array.

Syntax

UnicodeEncoding.GetChars(Byte[], Int32, Int32, Char[], Int32) has the following syntax.


public override int GetChars(
  byte[] bytes,//  w w  w  . j  a  v a2s.  c  o m
  int byteIndex,
  int byteCount,
  char[] chars,
  int charIndex
)

Parameters

UnicodeEncoding.GetChars(Byte[], Int32, Int32, Char[], Int32) has the following parameters.

  • bytes - The byte array containing the sequence of bytes to decode.
  • byteIndex - The index of the first byte to decode.
  • byteCount - The number of bytes to decode.
  • chars - The character array to contain the resulting set of characters.
  • charIndex - The index at which to start writing the resulting set of characters.

Returns

UnicodeEncoding.GetChars(Byte[], Int32, Int32, Char[], Int32) method returns The actual number of characters written into chars.

Example


// w  ww  .  j a  v a  2  s  . co m
using System;
using System.Text;

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding