C# UTF8Encoding GetByteCount(String)
Description
UTF8Encoding GetByteCount(String)
Calculates the
number of bytes produced by encoding the characters in the specified String.
Syntax
UTF8Encoding.GetByteCount(String)
has the following syntax.
public override int GetByteCount(
string chars
)
Parameters
UTF8Encoding.GetByteCount(String)
has the following parameters.
chars
- The String containing the set of characters to encode.
Returns
UTF8Encoding.GetByteCount(String)
method returns The number of bytes produced by encoding the specified characters.
Example
/*from ww w . ja va2 s .c om*/
using System;
using System.Text;
class UTF8EncodingExample {
public static void Main() {
String chars = "UTF8 Encoding Example";
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars);
Console.WriteLine(
"{0} bytes needed to encode string.", byteCount
);
}
}
The code above generates the following result.