Mega Code Archive

 
Categories / C# / Internationalization
 

Calculates the number of bytes produced by encoding a set of characters from the specified character array

using System; using System.Text; class MainClass {     public static void Main() {         Char[] chars = new Char[] {             '\u03a0', // Pi             '\u03a3'  // Sigma         };         UTF8Encoding utf8 = new UTF8Encoding();         int byteCount = utf8.GetByteCount(chars, 1, 2);         Console.WriteLine(             "{0} bytes needed to encode characters.", byteCount         );     } }