C# ASCIIEncoding GetChars(Byte[], Int32, Int32)

Description

ASCIIEncoding GetChars(Byte[], Int32, Int32) When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters.

Syntax

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


public virtual char[] GetChars(
  byte[] bytes,//w  ww .  j  ava 2s  .c om
  int index,
  int count
)

Parameters

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

  • bytes - The byte array containing the sequence of bytes to decode.
  • index - The index of the first byte to decode.
  • count - The number of bytes to decode.

Returns

ASCIIEncoding.GetChars(Byte[], Int32, Int32) method returns

Example


using System;//from w  w  w.j  ava2s. c  o m
using System.Text;

public class SamplesEncoding
{

    public static void Main()
    {
        Encoding u32LE = Encoding.GetEncoding("utf-32");
        Encoding u32BE = Encoding.GetEncoding("utf-32BE");
        String myStr = "za\u0306\u01FD\u03B2";

        byte[] barrBE = new byte[u32BE.GetByteCount(myStr)];
        u32BE.GetBytes(myStr, 0, myStr.Length, barrBE, 0);

        byte[] barrLE = new byte[u32LE.GetByteCount(myStr)];
        u32LE.GetBytes(myStr, 0, myStr.Length, barrLE, 0);

        Console.Write("{0,-25} :", u32BE.ToString());


        char[] chars = new char[100];
        u32BE.GetChars(barrLE, 0, 3, chars, 0);

        Console.WriteLine(chars);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding