C# Encoding GetCharCount(Byte[])
Description
Encoding 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
Encoding.GetCharCount(Byte[])
has the following syntax.
public virtual int GetCharCount(
byte[] bytes
)
Parameters
Encoding.GetCharCount(Byte[])
has the following parameters.
bytes
- The byte array containing the sequence of bytes to decode.
Returns
Encoding.GetCharCount(Byte[])
method returns The number of characters produced by decoding the specified sequence of
bytes.
Example
using System;//from www .j a v a 2 s. c o m
using System.Text;
public class SamplesEncoding
{
public static void Main()
{
Encoding enc = Encoding.GetEncoding("utf-32");
String myStr = "za\u0306\u01FD\u03B2";
byte[] bytes = new byte[enc.GetByteCount(myStr)];
enc.GetBytes(myStr, 0, myStr.Length, bytes, 0);
Console.Write(enc.ToString());
int iCC = enc.GetCharCount(bytes);
Console.Write(iCC);
}
}
The code above generates the following result.