C# Encoding GetByteCount(String)
Description
Encoding GetByteCount(String)
When overridden in a
derived class, calculates the number of bytes produced by encoding the characters
in the specified string.
Syntax
Encoding.GetByteCount(String)
has the following syntax.
public virtual int GetByteCount(
string s
)
Parameters
Encoding.GetByteCount(String)
has the following parameters.
s
- The string containing the set of characters to encode.
Returns
Encoding.GetByteCount(String)
method returns The number of bytes produced by encoding the specified characters.
Example
using System;// w w w. j a v a 2 s.c om
using System.Text;
public class SamplesEncoding
{
public static void Main()
{
String s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
Encoding enc = Encoding.UTF8;
Console.Write("{0,-30} :", enc.ToString());
int iBC = enc.GetByteCount(s);
Console.Write(" {0,-3}", iBC);
}
}
The code above generates the following result.