本文整理汇总了C#中System.Text.UnicodeEncoding.UnicodeEncoding构造函数的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding构造函数的具体用法?C# UnicodeEncoding怎么用?C# UnicodeEncoding使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.Text.UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding构造函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Text;
class UnicodeEncodingExample {
public static void Main() {
UnicodeEncoding unicode = new UnicodeEncoding();
String encodingName = unicode.EncodingName;
Console.WriteLine("Encoding name: " + encodingName);
}
}
示例2: Main
//引入命名空间
using System;
using System.Text;
class UnicodeEncodingExample {
public static void Main() {
// Create a UnicodeEncoding without parameters.
UnicodeEncoding unicode = new UnicodeEncoding();
// Create a UnicodeEncoding to support little-endian byte ordering
// and include the Unicode byte order mark.
UnicodeEncoding unicodeLittleEndianBOM =
new UnicodeEncoding(false, true);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeLittleEndianBOM));
// Create a UnicodeEncoding to support little-endian byte ordering
// and not include the Unicode byte order mark.
UnicodeEncoding unicodeLittleEndianNoBOM =
new UnicodeEncoding(false, false);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeLittleEndianNoBOM));
// Create a UnicodeEncoding to support big-endian byte ordering
// and include the Unicode byte order mark.
UnicodeEncoding unicodeBigEndianBOM =
new UnicodeEncoding(true, true);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeBigEndianBOM));
// Create a UnicodeEncoding to support big-endian byte ordering
// and not include the Unicode byte order mark.
UnicodeEncoding unicodeBigEndianNoBOM =
new UnicodeEncoding(true, false);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeBigEndianNoBOM));
}
public static void DescribeEquivalence(Boolean isEquivalent) {
Console.WriteLine(
"{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
);
}
}
示例3: Main
//引入命名空间
using System;
using System.Text;
public class SamplesUnicodeEncoding {
public static void Main() {
// Create an instance of UnicodeEncoding using little-endian byte order.
// This will be used for encoding.
UnicodeEncoding u16LE = new UnicodeEncoding( false, true );
// Create two instances of UnicodeEncoding using big-endian byte order: one with error detection and one without.
// These will be used for decoding.
UnicodeEncoding u16withED = new UnicodeEncoding( true, true, true );
UnicodeEncoding u16noED = new UnicodeEncoding( true, true, false );
// Create byte arrays from the same string containing the following characters:
// Latin Small Letter Z (U+007A)
// Latin Small Letter A (U+0061)
// Combining Breve (U+0306)
// Latin Small Letter AE With Acute (U+01FD)
// Greek Small Letter Beta (U+03B2)
// Latin Capital Letter U with Diaeresis (U+00DC)
String myStr = "za\u0306\u01FD\u03B2\u00DC";
// Encode the string using little-endian byte order.
byte[] myBytes = new byte[u16LE.GetByteCount( myStr )];
u16LE.GetBytes( myStr, 0, myStr.Length, myBytes, 0 );
// Decode the byte array with error detection.
Console.WriteLine( "Decoding with error detection:" );
PrintDecodedString( myBytes, u16withED );
// Decode the byte array without error detection.
Console.WriteLine( "Decoding without error detection:" );
PrintDecodedString( myBytes, u16noED );
}
// Decode the bytes and display the string.
public static void PrintDecodedString( byte[] bytes, Encoding enc ) {
try {
Console.WriteLine( " Decoded string: {0}", enc.GetString( bytes, 0, bytes.Length ) );
}
catch ( System.ArgumentException e ) {
Console.WriteLine( e.ToString() );
}
Console.WriteLine();
}
}