C# Encoding BigEndianUnicode
Description
Encoding BigEndianUnicode
Gets an encoding for the UTF-16
format that uses the big endian byte order.
Syntax
Encoding.BigEndianUnicode
has the following syntax.
public static Encoding BigEndianUnicode { get; }
Example
using System;//ww w. j av a2s . c o m
using System.IO;
using System.Text;
public class Class1
{
public static void Main(string[] args)
{
System.Text.Encoding encoding = System.Text.Encoding.BigEndianUnicode;
StreamReader reader = new StreamReader("TextFile.txt", encoding);
string line = reader.ReadLine();
while (line != null)
{
Console.WriteLine(line);
line = reader.ReadLine();
}
char[] myChars = new char[] { 'z', 'a', '\u0306', '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
Encoding enc = Encoding.BigEndianUnicode;
Console.Write("{0,-30} :", enc.ToString());
char[] chars = new char[100];
int iBC = enc.GetByteCount(chars);
Console.Write(" {0,-3}", iBC);
int iMBC = enc.GetMaxByteCount(chars.Length);
Console.Write(" {0,-3} :", iMBC);
byte[] bytes = enc.GetBytes(chars);
for (int i = 0; i < bytes.Length; i++)
Console.Write("{0:X2} ", bytes[i]);
Console.WriteLine();
}
}