C# UTF8Encoding GetCharCount(Byte[])

Description

UTF8Encoding 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

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


public virtual int GetCharCount(
  byte[] bytes
)

Parameters

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

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

Returns

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

Example


/*from  w ww  .  j  a va 2  s.c  om*/
using System;
using System.Text;

public class SamplesEncoding
{

    public static void Main()
    {
        Encoding u32LE = Encoding.GetEncoding("utf-32");
        String myStr = "za\u0306\u01FD\u03B2";
        byte[] barrLE = new byte[u32LE.GetByteCount(myStr)];
        u32LE.GetBytes(myStr, 0, myStr.Length, barrLE, 0);

        int iCC = u32LE.GetCharCount(barrLE);
        Console.WriteLine(" {0,-3}", iCC);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding