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

Description

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

Syntax

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


public override int GetCharCount(
  byte[] bytes,// ww w .j  a  v a2  s.  c  om
  int index,
  int count
)

Parameters

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

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

Example

The following code example demonstrates how to use the GetCharCount method to return the number of characters produced by decoding a range of elements in a byte array using UnicodeEncoding.


/*from  ww w . j  av a 2s  .com*/
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0};

        UnicodeEncoding Unicode = new UnicodeEncoding();
        int charCount = Unicode.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