public static void PrintCPBytes(string str, int codePage) { Encoding targetEncoding; byte[] encodedChars; // Gets the encoding for the specified code page. targetEncoding = Encoding.GetEncoding(codePage); // Gets the byte representation of the specified string. encodedChars = targetEncoding.GetBytes(str); // Prints the bytes. Console.WriteLine ("Byte representation of '{0}' in Code Page '{1}':", str, codePage); for (int i = 0; i < encodedChars.Length; i++) Console.WriteLine("Byte {0}: {1}", i, encodedChars[i]); }
{
Encoding targetEncoding;
byte[] encodedChars; // Gets the encoding for the specified code page.
targetEncoding = Encoding.GetEncoding(codePage); // Gets the byte representation of the specified string.
encodedChars = targetEncoding.GetBytes(str); // Prints the bytes.
Console.WriteLine
("Byte representation of '{0}' in Code Page '{1}':", str,
codePage);
for (int i = 0; i < encodedChars.Length; i++)
Console.WriteLine("Byte {0}: {1}", i, encodedChars[i]);
}