C# ASCIIEncoding GetCharCount(Byte[])

Description

ASCIIEncoding GetCharCount(Byte[]) When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array.

Syntax

ASCIIEncoding.GetCharCount(Byte[]) has the following syntax.


public virtual int GetCharCount(
  byte[] bytes
)

Parameters

ASCIIEncoding.GetCharCount(Byte[]) has the following parameters.

  • bytes - The byte array containing the sequence of bytes to decode.

Returns

ASCIIEncoding.GetCharCount(Byte[]) method returns The number of characters produced by decoding the specified sequence of bytes.

Example


using System;/* w w w .  j  a v a  2s. c  om*/
using System.Text;

public class SamplesEncoding
{

    public static void Main()
    {
        Encoding enc = Encoding.GetEncoding("utf-32");
        Encoding u32BE = Encoding.GetEncoding("utf-32BE");

        String myStr = "za\u0306\u01FD\u03B2";

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

        int iCC = enc.GetCharCount(bytes);
        Console.Write(" {0,-3}", iCC);

        int iMCC = enc.GetMaxCharCount(bytes.Length);
        Console.Write(" {0,-3} :", iMCC);

        char[] chars = enc.GetChars(bytes);
        Console.WriteLine(chars);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding