Mega Code Archive

 
Categories / C# / Internationalization
 

Calculates the number of bytes produced by encoding the characters in the specified String

using System; using System.Text; class UTF8EncodingExample {     public static void Main() {         String chars = "this is a test";         UTF8Encoding utf8 = new UTF8Encoding();         int byteCount = utf8.GetByteCount(chars);         Console.WriteLine("{0} bytes needed to encode string.", byteCount);     } }