C# UTF8Encoding GetCharCount(Byte[], Int32, Int32)

Description

UTF8Encoding GetCharCount(Byte[], Int32, Int32) Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

Syntax

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


public override int GetCharCount(
  byte[] bytes,/*from  w w  w .ja va2  s  . c o  m*/
  int index,
  int count
)

Parameters

UTF8Encoding.GetCharCount(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

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

Example


using System;/*from  ww  w .  ja  v a2s.  c  om*/
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {
             86,  84,  71,  56,  32,  69, 110,
             69, 120,  97, 109, 112, 108, 101
        };

        UTF8Encoding utf8 = new UTF8Encoding();
        int charCount = utf8.GetCharCount(bytes, 2, 8);
        Console.WriteLine(charCount);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding