C# ASCIIEncoding GetByteCount(String)
Description
ASCIIEncoding GetByteCount(String)
Calculates the
number of bytes produced by encoding the characters in the specified String.
Syntax
ASCIIEncoding.GetByteCount(String)
has the following syntax.
public override int GetByteCount(
string chars
)
Parameters
ASCIIEncoding.GetByteCount(String)
has the following parameters.
chars
- The String containing the set of characters to encode.
Returns
ASCIIEncoding.GetByteCount(String)
method returns The number of bytes produced by encoding the specified characters.
Example
using System;// w w w . j a v a2 s . c o m
using System.Text;
class ASCIIEncodingExample {
public static void Main() {
String chars = "ASCII Encoding Example";
ASCIIEncoding ascii = new ASCIIEncoding();
int byteCount = ascii.GetByteCount(chars);
Console.WriteLine(
"{0} bytes needed to encode string.", byteCount
);
}
}
The code above generates the following result.