C# UTF8Encoding GetByteCount(Char[], Int32, Int32)

Description

UTF8Encoding GetByteCount(Char[], Int32, Int32) Calculates the number of bytes produced by encoding a set of characters from the specified character array.

Syntax

UTF8Encoding.GetByteCount(Char[], Int32, Int32) has the following syntax.


public override int GetByteCount(
  char[] chars,//from   www  .  jav  a  2  s  .c o m
  int index,
  int count
)

Parameters

UTF8Encoding.GetByteCount(Char[], Int32, Int32) has the following parameters.

  • chars - The character array containing the set of characters to encode.
  • index - The index of the first character to encode.
  • count - The number of characters to encode.

Returns

UTF8Encoding.GetByteCount(Char[], Int32, Int32) method returns The number of bytes produced by encoding the specified characters.

Example


/*from w  ww .j a v a2 s . c o m*/
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        Char[] chars = new Char[] {
            '\u0023', // #
            '\u0025', // %
            '\u03a0', // Pi
            '\u03a3'  // Sigma
        };

        UTF8Encoding utf8 = new UTF8Encoding();
        int byteCount = utf8.GetByteCount(chars, 1, 2);
        Console.WriteLine(byteCount);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding