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

Description

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

Syntax

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


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

Parameters

ASCIIEncoding.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

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

Example


using System;/*from   w ww.ja  va2s . c  o m*/
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {
             65,  83,  67,  73,  73,  32,  69,
            110,  99, 111, 100, 105, 110, 103,
             32,  69, 120,  97, 109, 112, 108, 101
        };

        ASCIIEncoding ascii = new ASCIIEncoding();

        int charCount = ascii.GetCharCount(bytes, 6, 8);
        chars = new Char[charCount];
        int charsDecodedCount = ascii.GetChars(bytes, 6, 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