C# Encoding GetMaxCharCount

Description

Encoding GetMaxCharCount When overridden in a derived class, calculates the maximum number of characters produced by decoding the specified number of bytes.

Syntax

Encoding.GetMaxCharCount has the following syntax.


public abstract int GetMaxCharCount(
  int byteCount
)

Parameters

Encoding.GetMaxCharCount has the following parameters.

  • byteCount - The number of bytes to decode.

Returns

Encoding.GetMaxCharCount method returns The maximum number of characters produced by decoding the specified number of bytes.

Example


using System;// www  .  java  2 s .  c  om
using System.Text;

public class SamplesEncoding
{

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

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

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding