Encoding Encoding Encoding Encoding Class

定义

表示字符编码。Represents a character encoding.

public ref class Encoding abstract : ICloneable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public abstract class Encoding : ICloneable
type Encoding = class
    interface ICloneable
Public MustInherit Class Encoding
Implements ICloneable
继承
EncodingEncodingEncodingEncoding
派生
属性
实现

示例

下面的示例将字符串从一种编码转换为另一种编码。The following example converts a string from one encoding to another.

备注

在此示例中,byte [] 数组是包含编码数据的唯一类型。The byte[] array is the only type in this example that contains the encoded data. .Net Char 和 String 类型本身是 unicode,因此GetChars调用会将数据解码回 unicode。The .NET Char and String types are themselves Unicode, so the GetChars call decodes the data back to Unicode.

using namespace System;
using namespace System::Text;

int main()
{
   String^ unicodeString = "This string contains the unicode character Pi (\u03a0)";
   
   // Create two different encodings.
   Encoding^ ascii = Encoding::ASCII;
   Encoding^ unicode = Encoding::Unicode;
   
   // Convert the string into a byte array.
   array<Byte>^unicodeBytes = unicode->GetBytes( unicodeString );
   
   // Perform the conversion from one encoding to the other.
   array<Byte>^asciiBytes = Encoding::Convert( unicode, ascii, unicodeBytes );
   
   // Convert the new Byte into[] a char and[] then into a string.
   array<Char>^asciiChars = gcnew array<Char>(ascii->GetCharCount( asciiBytes, 0, asciiBytes->Length ));
   ascii->GetChars( asciiBytes, 0, asciiBytes->Length, asciiChars, 0 );
   String^ asciiString = gcnew String( asciiChars );
   
   // Display the strings created before and after the conversion.
   Console::WriteLine( "Original String*: {0}", unicodeString );
   Console::WriteLine( "Ascii converted String*: {0}", asciiString );
}
// The example displays the following output:
//    Original string: This string contains the unicode character Pi (Π)
//    Ascii converted string: This string contains the unicode character Pi (?)
using System;
using System.Text;

class Example
{
   static void Main()
   {
      string unicodeString = "This string contains the unicode character Pi (\u03a0)";

      // Create two different encodings.
      Encoding ascii = Encoding.ASCII;
      Encoding unicode = Encoding.Unicode;

      // Convert the string into a byte array.
      byte[] unicodeBytes = unicode.GetBytes(unicodeString);

      // Perform the conversion from one encoding to the other.
      byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
         
      // Convert the new byte[] into a char[] and then into a string.
      char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
      ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
      string asciiString = new string(asciiChars);

      // Display the strings created before and after the conversion.
      Console.WriteLine("Original string: {0}", unicodeString);
      Console.WriteLine("Ascii converted string: {0}", asciiString);
   }
}
// The example displays the following output:
//    Original string: This string contains the unicode character Pi (Π)
//    Ascii converted string: This string contains the unicode character Pi (?)
Imports System.Text

Class Example
   Shared Sub Main()
      Dim unicodeString As String = "This string contains the unicode character Pi (" & ChrW(&H03A0) & ")"

      ' Create two different encodings.
      Dim ascii As Encoding = Encoding.ASCII
      Dim unicode As Encoding = Encoding.Unicode

      ' Convert the string into a byte array.
      Dim unicodeBytes As Byte() = unicode.GetBytes(unicodeString)

      ' Perform the conversion from one encoding to the other.
      Dim asciiBytes As Byte() = Encoding.Convert(unicode, ascii, unicodeBytes)

      ' Convert the new byte array into a char array and then into a string.
      Dim asciiChars(ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)-1) As Char
      ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
      Dim asciiString As New String(asciiChars)

      ' Display the strings created before and after the conversion.
      Console.WriteLine("Original string: {0}", unicodeString)
      Console.WriteLine("Ascii converted string: {0}", asciiString)
   End Sub
End Class
' The example displays the following output:
'    Original string: This string contains the unicode character Pi (Π)
'    Ascii converted string: This string contains the unicode character Pi (?)

注解

编码是将一组 Unicode 字符转换为一个字节序列的过程。Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. 相反,解码是将编码字节序列转换为一组 Unicode 字符的过程。In contrast, decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters. 有关 Unicode 转换格式(UTFs)和支持Encoding的其他编码的信息,请参阅.net 中的字符编码For information about the Unicode Transformation Formats (UTFs) and other encodings supported by Encoding, see Character Encoding in .NET.

Encoding请注意,旨在对 Unicode 字符而不是任意二进制数据(如字节数组)进行操作。Note that Encoding is intended to operate on Unicode characters instead of arbitrary binary data, such as byte arrays. 如果必须将任意二进制数据编码为文本,则应使用诸如 uuencode 这样的协议,该协议是由等方法Convert.ToBase64CharArray实现的。If you must encode arbitrary binary data into text, you should use a protocol such as uuencode, which is implemented by methods such as Convert.ToBase64CharArray.

.Net 提供Encoding类的以下实现来支持当前的 Unicode 编码和其他编码:.NET provides the following implementations of the Encoding class to support current Unicode encodings and other encodings:

  • ASCIIEncoding将 Unicode 字符编码为单个7位 ASCII 字符。ASCIIEncoding encodes Unicode characters as single 7-bit ASCII characters. 此编码仅支持 U + 0000 到 U + 007F 之间的字符值。This encoding only supports character values between U+0000 and U+007F. 代码页20127。Code page 20127. 还可通过ASCII属性获得。Also available through the ASCII property.

  • UTF7Encoding使用 UTF-7 编码对 Unicode 字符进行编码。UTF7Encoding encodes Unicode characters using the UTF-7 encoding. 此编码支持所有 Unicode 字符值。This encoding supports all Unicode character values. 代码页65000。Code page 65000. 还可通过UTF7属性获得。Also available through the UTF7 property.

  • UTF8Encoding使用 UTF-8 编码对 Unicode 字符进行编码。UTF8Encoding encodes Unicode characters using the UTF-8 encoding. 此编码支持所有 Unicode 字符值。This encoding supports all Unicode character values. 代码页65001。Code page 65001. 还可通过UTF8属性获得。Also available through the UTF8 property.

  • UnicodeEncoding使用 UTF-16 编码对 Unicode 字符进行编码。UnicodeEncoding encodes Unicode characters using the UTF-16 encoding. 支持 little endian 和大型 endian 字节顺序。Both little endian and big endian byte orders are supported. 还可通过Unicode属性BigEndianUnicode和属性获取。Also available through the Unicode property and the BigEndianUnicode property.

  • UTF32Encoding使用 32 UTF-8 编码对 Unicode 字符进行编码。UTF32Encoding encodes Unicode characters using the UTF-32 encoding. 支持 little endian (代码页12000)和大型 endian (代码页12001)字节顺序。Both little endian (code page 12000) and big endian (code page 12001) byte orders are supported. 还可通过UTF32属性获得。Also available through the UTF32 property.

Encoding类主要用于在不同的编码和 Unicode 之间转换。The Encoding class is primarily intended to convert between different encodings and Unicode. 通常,其中一个派生的 Unicode 类是适用于你的应用程序的正确选择。Often one of the derived Unicode classes is the correct choice for your app.

使用方法可获取其他编码,并GetEncodings调用方法来获取所有编码的列表。 GetEncodingUse the GetEncoding method to obtain other encodings, and call the GetEncodings method to get a list of all encodings.

下表列出了 .NET Framework 和 .NET Core 支持的编码。The following table lists the encodings supported by .NET Framework and .NET Core. 它列出了每个编码的代码页编号以及编码的EncodingInfo.NameEncodingInfo.DisplayName属性的值。It lists each encoding's code page number and the values of the encoding's EncodingInfo.Name and EncodingInfo.DisplayName properties. " .NET Framework 支持" 和 " .net Core 支持" 列中的复选标记指示该 .net 实现本机支持代码页,而不考虑基础平台。A check mark in the .NET Framework support and .NET Core support columns indicates that the code page is natively supported by that .NET implementation, regardless of the underlying platform. 对于 .NET Framework,表中列出的其他编码的可用性取决于操作系统。For .NET Framework, the availability of other encodings listed in the table depends on the operating system. 对于 .net Core,可以通过使用System.Text.CodePagesEncodingProvider类或System.Text.EncodingProvider从类派生来使用其他编码。For .NET Core, other encodings are available by using the System.Text.CodePagesEncodingProvider class or by deriving from the System.Text.EncodingProvider class.

备注

EncodingInfo.Name属性对应于国际标准的代码页不一定完全符合该标准。Code pages whose EncodingInfo.Name property corresponds to an international standard do not necessarily comply in full with that standard.

代码页Code page nameName 显示名称Display name .NET Framework 支持.NET Framework support .NET Core 支持.NET Core support
3737 IBM037IBM037 IBM EBCDIC (美国-加拿大)IBM EBCDIC (US-Canada)
437437 IBM437IBM437 OEM 美国OEM United States
500500 IBM500IBM500 IBM EBCDIC (国际)IBM EBCDIC (International)
708708 ASMO-708ASMO-708 阿拉伯语(ASMO 708)Arabic (ASMO 708)
720720 DOS-720DOS-720 阿拉伯语(DOS)Arabic (DOS)
737737 ibm737ibm737 希腊语(DOS)Greek (DOS)
775775 ibm775ibm775 波罗的语(DOS)Baltic (DOS)
850850 ibm850ibm850 西欧(DOS)Western European (DOS)
852852 ibm852ibm852 中欧语(DOS)Central European (DOS)
855855 IBM855IBM855 OEM 西里尔语OEM Cyrillic
857857 ibm857ibm857 土耳其语(DOS)Turkish (DOS)
858858 IBM00858IBM00858 OEM 多语言拉丁语 IOEM Multilingual Latin I
860860 IBM860IBM860 葡萄牙语(DOS)Portuguese (DOS)
861861 ibm861ibm861 冰岛语(DOS)Icelandic (DOS)
862862 DOS-862DOS-862 希伯来语(DOS)Hebrew (DOS)
863863 IBM863IBM863 加拿大法语(DOS)French Canadian (DOS)
864864 IBM864IBM864 阿拉伯语(864)Arabic (864)
865865 IBM865IBM865 北欧语(DOS)Nordic (DOS)
866866 cp866cp866 西里尔语(DOS)Cyrillic (DOS)
869869 ibm869ibm869 现代希腊语(DOS)Greek, Modern (DOS)
870870 IBM870IBM870 IBM EBCDIC (多语言拉丁语-2)IBM EBCDIC (Multilingual Latin-2)
874874 windows-874windows-874 泰语(Windows)Thai (Windows)
875875 cp875cp875 IBM EBCDIC (现代希腊语)IBM EBCDIC (Greek Modern)
932932 shift_jisshift_jis 日语(Shift-jis)Japanese (Shift-JIS)
936936 gb2312gb2312 简体中文(GB2312)Chinese Simplified (GB2312)
949949 ks_c_5601-1987ks_c_5601-1987 朝鲜语Korean
950950 big5big5 繁体中文(Big5)Chinese Traditional (Big5)
10261026 IBM1026IBM1026 IBM EBCDIC (土耳其拉丁语-5)IBM EBCDIC (Turkish Latin-5)
10471047 IBM01047IBM01047 IBM 拉丁语-1IBM Latin-1
11401140 IBM01140IBM01140 IBM EBCDIC (美国-加拿大-欧洲)IBM EBCDIC (US-Canada-Euro)
11411141 IBM01141IBM01141 IBM EBCDIC (德国-欧洲)IBM EBCDIC (Germany-Euro)
11421142 IBM01142IBM01142 IBM EBCDIC (丹麦-挪威-欧洲)IBM EBCDIC (Denmark-Norway-Euro)
11431143 IBM01143IBM01143 IBM EBCDIC (芬兰-瑞典-欧洲)IBM EBCDIC (Finland-Sweden-Euro)
11441144 IBM01144IBM01144 IBM EBCDIC (意大利-欧洲)IBM EBCDIC (Italy-Euro)
11451145 IBM01145IBM01145 IBM EBCDIC (西班牙-欧洲)IBM EBCDIC (Spain-Euro)
11461146 IBM01146IBM01146 IBM EBCDIC (英国-欧洲)IBM EBCDIC (UK-Euro)
11471147 IBM01147IBM01147 IBM EBCDIC (法国-欧洲)IBM EBCDIC (France-Euro)
11481148 IBM01148IBM01148 IBM EBCDIC (国际-欧洲)IBM EBCDIC (International-Euro)
11491149 IBM01149IBM01149 IBM EBCDIC (冰岛语-欧洲)IBM EBCDIC (Icelandic-Euro)
12001200 utf-16utf-16 UnicodeUnicode
12011201 unicodeFFFEunicodeFFFE Unicode (大字节序)Unicode (Big endian)
12501250 windows-1250windows-1250 中欧语(Windows)Central European (Windows)
12511251 windows-1251windows-1251 西里尔语(Windows)Cyrillic (Windows)
12521252 Windows-1252Windows-1252 西欧(Windows)Western European (Windows)
12531253 windows-1253windows-1253 希腊语(Windows)Greek (Windows)
12541254 windows-1254windows-1254 土耳其语(Windows)Turkish (Windows)
12551255 windows-1255windows-1255 希伯来语(Windows)Hebrew (Windows)
12561256 windows-1256windows-1256 阿拉伯语(Windows)Arabic (Windows)
12571257 windows-1257windows-1257 波罗的语(Windows)Baltic (Windows)
12581258 windows-1258windows-1258 越南语(Windows)Vietnamese (Windows)
13611361 JohabJohab 韩语(Johab)Korean (Johab)
1000010000 macintoshmacintosh 西欧(Mac)Western European (Mac)
1000110001 x-mac-日语x-mac-japanese 日语(Mac)Japanese (Mac)
1000210002 x-mac-chinesetradx-mac-chinesetrad 繁体中文(Mac)Chinese Traditional (Mac)
1000310003 x-mac-韩语x-mac-korean 朝鲜语(Mac)Korean (Mac)
1000410004 x-mac-arabicx-mac-arabic 阿拉伯语(Mac)Arabic (Mac)
1000510005 x-mac-hebrewx-mac-hebrew 希伯来语(Mac)Hebrew (Mac)
1000610006 x-mac-希腊语x-mac-greek 希腊语(Mac)Greek (Mac)
1000710007 x-mac-cyrillicx-mac-cyrillic 西里尔语(Mac)Cyrillic (Mac)
1000810008 x-mac-chinesesimpx-mac-chinesesimp 简体中文(Mac)Chinese Simplified (Mac)
1001010010 x-macx-mac-romanian 罗马尼亚语(Mac)Romanian (Mac)
1001710017 x-mac-乌克兰语x-mac-ukrainian 乌克兰语(Mac)Ukrainian (Mac)
1002110021 x-mac-泰语x-mac-thai 泰语(Mac)Thai (Mac)
1002910029 x-mac-cex-mac-ce 中欧语(Mac)Central European (Mac)
1007910079 x-mac-冰岛语x-mac-icelandic 冰岛语(Mac)Icelandic (Mac)
1008110081 x-mac-turkishx-mac-turkish 土耳其语(Mac)Turkish (Mac)
1008210082 x-mac-克罗地亚语x-mac-croatian 克罗地亚语(Mac)Croatian (Mac)
1200012000 utf-32utf-32 Unicode (UTF-32)Unicode (UTF-32)
1200112001 utf-32BEutf-32BE Unicode (UTF-16 32 大字节序)Unicode (UTF-32 Big endian)
2000020000 x-中文-CNSx-Chinese-CNS 繁体中文(CNS)Chinese Traditional (CNS)
2000120001 x-cp20001x-cp20001 TCA 台湾TCA Taiwan
2000220002 x-中文-Etenx-Chinese-Eten 繁体中文(Eten)Chinese Traditional (Eten)
2000320003 x-cp20003x-cp20003 IBM5550 台湾IBM5550 Taiwan
2000420004 x-cp20004x-cp20004 TeleText 台湾TeleText Taiwan
2000520005 x-cp20005x-cp20005 Wang 台湾Wang Taiwan
2010520105 x-IA5x-IA5 西欧(IA5)Western European (IA5)
2010620106 x-IA5-德语x-IA5-German 德语(IA5)German (IA5)
2010720107 x IA5-瑞典语x-IA5-Swedish 瑞典语(IA5)Swedish (IA5)
2010820108 x-IA5-Norwegianx-IA5-Norwegian 挪威语(IA5)Norwegian (IA5)
2012720127 us-asciius-ascii US-ASCIIUS-ASCII
2026120261 x-cp20261x-cp20261 T.61T.61
2026920269 x-cp20269x-cp20269 ISO-6937ISO-6937
2027320273 IBM273IBM273 IBM EBCDIC (德国)IBM EBCDIC (Germany)
2027720277 IBM277IBM277 IBM EBCDIC (丹麦-挪威)IBM EBCDIC (Denmark-Norway)
2027820278 IBM278IBM278 IBM EBCDIC (芬兰-瑞典)IBM EBCDIC (Finland-Sweden)
2028020280 IBM280IBM280 IBM EBCDIC (意大利)IBM EBCDIC (Italy)
2028420284 IBM284IBM284 IBM EBCDIC (西班牙)IBM EBCDIC (Spain)
2028520285 IBM285IBM285 IBM EBCDIC (英国)IBM EBCDIC (UK)
2029020290 IBM290IBM290 IBM EBCDIC (日语片假名)IBM EBCDIC (Japanese katakana)
2029720297 IBM297IBM297 IBM EBCDIC (法国)IBM EBCDIC (France)
2042020420 IBM420IBM420 IBM EBCDIC (阿拉伯语)IBM EBCDIC (Arabic)
2042320423 IBM423IBM423 IBM EBCDIC (希腊语)IBM EBCDIC (Greek)
2042420424 IBM424IBM424 IBM EBCDIC (希伯来语)IBM EBCDIC (Hebrew)
2083320833 x-EBCDIC-KoreanExtendedx-EBCDIC-KoreanExtended IBM EBCDIC (朝鲜语扩展)IBM EBCDIC (Korean Extended)
2083820838 IBM-泰语IBM-Thai IBM EBCDIC (泰语)IBM EBCDIC (Thai)
2086620866 koi8-rkoi8-r 西里尔语(KOI8-RU-R)Cyrillic (KOI8-R)
2087120871 IBM871IBM871 IBM EBCDIC (冰岛语)IBM EBCDIC (Icelandic)
2088020880 IBM880IBM880 IBM EBCDIC (西里尔语俄语)IBM EBCDIC (Cyrillic Russian)
2090520905 IBM905IBM905 IBM EBCDIC (土耳其语)IBM EBCDIC (Turkish)
2092420924 IBM00924IBM00924 IBM 拉丁语-1IBM Latin-1
2093220932 EUC-JPEUC-JP 日语(JIS 0208-1990 和0212-1990)Japanese (JIS 0208-1990 and 0212-1990)
2093620936 x-cp20936x-cp20936 简体中文(GB2312-80)Chinese Simplified (GB2312-80)
2094920949 x-cp20949x-cp20949 韩语 WansungKorean Wansung
2102521025 cp1025cp1025 IBM EBCDIC (西里尔语塞尔维亚语-保加利亚语)IBM EBCDIC (Cyrillic Serbian-Bulgarian)
2186621866 koi8-ru-ukoi8-u 西里尔语(KOI8-RU)Cyrillic (KOI8-U)
2859128591 iso-8859-1iso-8859-1 西欧(ISO)Western European (ISO)
2859228592 iso-8859-2iso-8859-2 中欧语(ISO)Central European (ISO)
2859328593 iso-8859-3iso-8859-3 拉丁语3(ISO)Latin 3 (ISO)
2859428594 iso-8859-4iso-8859-4 波罗的语(ISO)Baltic (ISO)
2859528595 iso-8859-5iso-8859-5 西里尔语(ISO)Cyrillic (ISO)
2859628596 iso-8859-6iso-8859-6 阿拉伯语(ISO)Arabic (ISO)
2859728597 iso-8859-7iso-8859-7 希腊语(ISO)Greek (ISO)
2859828598 iso-8859-8iso-8859-8 希伯来语(ISO-视觉对象)Hebrew (ISO-Visual)
2859928599 iso-8859-9iso-8859-9 土耳其语(ISO)Turkish (ISO)
2860328603 iso-8859-13iso-8859-13 爱沙尼亚语(ISO)Estonian (ISO)
2860528605 iso-8859-15iso-8859-15 拉丁语9(ISO)Latin 9 (ISO)
2900129001 x-Europax-Europa 欧洲Europa
3859838598 iso-8859-8-iiso-8859-8-i 希伯来语(ISO-逻辑)Hebrew (ISO-Logical)
5022050220 iso-2022-jpiso-2022-jp 日语(JIS)Japanese (JIS)
5022150221 csISO2022JPcsISO2022JP 日语(JIS-允许1字节假名)Japanese (JIS-Allow 1 byte Kana)
5022250222 iso-2022-jpiso-2022-jp 日语(JIS-允许1字节假名-SO/SI)Japanese (JIS-Allow 1 byte Kana - SO/SI)
5022550225 iso-2022-kriso-2022-kr 朝鲜语(ISO)Korean (ISO)
5022750227 x-cp50227x-cp50227 简体中文(ISO-2022)Chinese Simplified (ISO-2022)
5193251932 euc-jpeuc-jp 日语(EUC)Japanese (EUC)
5193651936 EUC-CNEUC-CN 简体中文(EUC)Chinese Simplified (EUC)
5194951949 euc-kreuc-kr 韩语(EUC)Korean (EUC)
5293652936 hz-gb-2312hz-gb-2312 简体中文(HZ)Chinese Simplified (HZ)
5493654936 GB18030GB18030 简体中文(GB18030)Chinese Simplified (GB18030)
5700257002 x-iscii-dex-iscii-de ISCII 梵文ISCII Devanagari
5700357003 x-iscii-bex-iscii-be ISCII 孟加拉语ISCII Bengali
5700457004 x-iscii-tax-iscii-ta ISCII 泰米尔语ISCII Tamil
5700557005 x-iscii-tex-iscii-te ISCII 泰卢固语ISCII Telugu
5700657006 x-iscii-asx-iscii-as ISCII 阿萨姆语ISCII Assamese
5700757007 x-iscii-orx-iscii-or ISCII 奥里雅语ISCII Oriya
5700857008 x-iscii-kax-iscii-ka ISCII 埃纳德文ISCII Kannada
5700957009 x-iscii-max-iscii-ma ISCII 马拉雅拉姆语ISCII Malayalam
5701057010 x-iscii-gux-iscii-gu ISCII 古吉拉特语ISCII Gujarati
5701157011 x-iscii-pax-iscii-pa ISCII 旁遮普语ISCII Punjabi
6500065000 utf-7utf-7 Unicode (UTF-7)Unicode (UTF-7)
6500165001 utf-8utf-8 Unicode (UTF-8)Unicode (UTF-8)

下面的示例调用GetEncoding(Int32)GetEncoding(String)方法以获取希腊语(Windows)代码页编码。The following example calls the GetEncoding(Int32) and GetEncoding(String) methods to get the Greek (Windows) code page encoding. 它将方法Encoding调用返回的对象进行比较,以显示它们相等,然后 maps 显示每个字符在希腊语字母表中的 Unicode 码位和相应的代码页值。It compares the Encoding objects returned by the method calls to show that they are equal, and then maps displays the Unicode code point and the corresponding code page value for each character in the Greek alphabet.

using System;
using System.Text;

public class Example
{
   public static void Main()
   {
      Encoding enc = Encoding.GetEncoding(1253);
      Encoding altEnc = Encoding.GetEncoding("windows-1253");
      Console.WriteLine("{0} = Code Page {1}: {2}", enc.EncodingName,
                        altEnc.CodePage, enc.Equals(altEnc));
      string greekAlphabet = "Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η " +
                             "Θ θ Ι ι Κ κ Λ λ Μ μ Ν ν Ξ ξ " +
                             "Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ υ " +
                             "Φ φ Χ χ Ψ ψ Ω ω";
      Console.OutputEncoding = Encoding.UTF8;
      byte[] bytes = enc.GetBytes(greekAlphabet);
      Console.WriteLine("{0,-12} {1,20} {2,20:X2}", "Character",
                        "Unicode Code Point", "Code Page 1253");
      for (int ctr = 0; ctr < bytes.Length; ctr++) {
         if (greekAlphabet[ctr].Equals(' '))
            continue;

         Console.WriteLine("{0,-12} {1,20} {2,20:X2}", greekAlphabet[ctr],
                           GetCodePoint(greekAlphabet[ctr]), bytes[ctr]);
      }
   }

   private static string GetCodePoint(char ch)
   {
      string retVal = "u+";
      byte[] bytes = Encoding.Unicode.GetBytes(ch.ToString());
      for (int ctr = bytes.Length - 1; ctr >= 0; ctr--)
         retVal += bytes[ctr].ToString("X2");

      return retVal;
   }
}
// The example displays the following output:
//       Character      Unicode Code Point       Code Page 1253
//       Α                          u+0391                   C1
//       α                          u+03B1                   E1
//       Β                          u+0392                   C2
//       β                          u+03B2                   E2
//       Γ                          u+0393                   C3
//       γ                          u+03B3                   E3
//       Δ                          u+0394                   C4
//       δ                          u+03B4                   E4
//       Ε                          u+0395                   C5
//       ε                          u+03B5                   E5
//       Ζ                          u+0396                   C6
//       ζ                          u+03B6                   E6
//       Η                          u+0397                   C7
//       η                          u+03B7                   E7
//       Θ                          u+0398                   C8
//       θ                          u+03B8                   E8
//       Ι                          u+0399                   C9
//       ι                          u+03B9                   E9
//       Κ                          u+039A                   CA
//       κ                          u+03BA                   EA
//       Λ                          u+039B                   CB
//       λ                          u+03BB                   EB
//       Μ                          u+039C                   CC
//       μ                          u+03BC                   EC
//       Ν                          u+039D                   CD
//       ν                          u+03BD                   ED
//       Ξ                          u+039E                   CE
//       ξ                          u+03BE                   EE
//       Ο                          u+039F                   CF
//       ο                          u+03BF                   EF
//       Π                          u+03A0                   D0
//       π                          u+03C0                   F0
//       Ρ                          u+03A1                   D1
//       ρ                          u+03C1                   F1
//       Σ                          u+03A3                   D3
//       σ                          u+03C3                   F3
//       ς                          u+03C2                   F2
//       Τ                          u+03A4                   D4
//       τ                          u+03C4                   F4
//       Υ                          u+03A5                   D5
//       υ                          u+03C5                   F5
//       Φ                          u+03A6                   D6
//       φ                          u+03C6                   F6
//       Χ                          u+03A7                   D7
//       χ                          u+03C7                   F7
//       Ψ                          u+03A8                   D8
//       ψ                          u+03C8                   F8
//       Ω                          u+03A9                   D9
//       ω                          u+03C9                   F9
Imports System.Text

Module Example
   Public Sub Main()
      Dim enc As Encoding = Encoding.GetEncoding(1253)
      Dim altEnc As Encoding = Encoding.GetEncoding("windows-1253")
      Console.WriteLine("{0} = Code Page {1}: {2}", enc.EncodingName,
                        altEnc.CodePage, enc.Equals(altEnc))
      Dim greekAlphabet As String = "Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η " +
                                    "Θ θ Ι ι Κ κ Λ λ Μ μ Ν ν Ξ ξ " +
                                    "Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ υ " +
                                    "Φ φ Χ χ Ψ ψ Ω ω"
      Console.OutputEncoding = Encoding.UTF8
      Dim bytes() As Byte = enc.GetBytes(greekAlphabet)
      Console.WriteLine("{0,-12} {1,20} {2,20:X2}", "Character",
                        "Unicode Code Point", "Code Page 1253")
      For ctr As Integer = 0 To bytes.Length - 1
         If greekAlphabet(ctr).Equals(" "c) Then Continue For

         Console.WriteLine("{0,-12} {1,20} {2,20:X2}", greekAlphabet(ctr),
                           GetCodePoint(greekAlphabet(ctr)), bytes(ctr))
      Next

   End Sub
   
   Private Function GetCodePoint(ch As String) As String
      Dim retVal As String = "u+"
      Dim bytes() As Byte = Encoding.Unicode.GetBytes(ch)
      For ctr As Integer = bytes.Length - 1 To 0 Step -1
         retVal += bytes(ctr).ToString("X2")
      Next
      Return retVal
   End Function
End Module
' The example displays the following output:
'    Character      Unicode Code Point       Code Page 1253
'    Α                          u+0391                   C1
'    α                          u+03B1                   E1
'    Β                          u+0392                   C2
'    β                          u+03B2                   E2
'    Γ                          u+0393                   C3
'    γ                          u+03B3                   E3
'    Δ                          u+0394                   C4
'    δ                          u+03B4                   E4
'    Ε                          u+0395                   C5
'    ε                          u+03B5                   E5
'    Ζ                          u+0396                   C6
'    ζ                          u+03B6                   E6
'    Η                          u+0397                   C7
'    η                          u+03B7                   E7
'    Θ                          u+0398                   C8
'    θ                          u+03B8                   E8
'    Ι                          u+0399                   C9
'    ι                          u+03B9                   E9
'    Κ                          u+039A                   CA
'    κ                          u+03BA                   EA
'    Λ                          u+039B                   CB
'    λ                          u+03BB                   EB
'    Μ                          u+039C                   CC
'    μ                          u+03BC                   EC
'    Ν                          u+039D                   CD
'    ν                          u+03BD                   ED
'    Ξ                          u+039E                   CE
'    ξ                          u+03BE                   EE
'    Ο                          u+039F                   CF
'    ο                          u+03BF                   EF
'    Π                          u+03A0                   D0
'    π                          u+03C0                   F0
'    Ρ                          u+03A1                   D1
'    ρ                          u+03C1                   F1
'    Σ                          u+03A3                   D3
'    σ                          u+03C3                   F3
'    ς                          u+03C2                   F2
'    Τ                          u+03A4                   D4
'    τ                          u+03C4                   F4
'    Υ                          u+03A5                   D5
'    υ                          u+03C5                   F5
'    Φ                          u+03A6                   D6
'    φ                          u+03C6                   F6
'    Χ                          u+03A7                   D7
'    χ                          u+03C7                   F7
'    Ψ                          u+03A8                   D8
'    ψ                          u+03C8                   F8
'    Ω                          u+03A9                   D9
'    ω                          u+03C9                   F9

如果要转换的数据仅在顺序块(如从流中读取的数据)中可用,或者如果数据量很大以致需要分为更小块,则应使用DecoderGetDecoder Encoder派生类的GetEncoder方法或方法。If the data to be converted is available only in sequential blocks (such as data read from a stream) or if the amount of data is so large that it needs to be divided into smaller blocks, you should use the Decoder or the Encoder provided by the GetDecoder method or the GetEncoder method, respectively, of a derived class.

UTF-16 和32编码器可以使用大 endian 字节顺序(首先是最重要的字节),也可以是 little endian 字节顺序(首先是最不重要的字节)。The UTF-16 and the UTF-32 encoders can use the big endian byte order (most significant byte first) or the little endian byte order (least significant byte first). 例如,拉丁文大写字母 A (U + 0041)按以下方式序列化(十六进制):For example, the Latin Capital Letter A (U+0041) is serialized as follows (in hexadecimal):

  • UTF-16 大 endian 字节顺序:00 41UTF-16 big endian byte order: 00 41

  • UTF-16 little endian 字节顺序:41 00UTF-16 little endian byte order: 41 00

  • 32大 endian 字节顺序:00 00 00 41UTF-32 big endian byte order: 00 00 00 41

  • 32 little endian 字节顺序:41 00 00 00UTF-32 little endian byte order: 41 00 00 00

使用本机字节顺序存储 Unicode 字符通常更有效。It is generally more efficient to store Unicode characters using the native byte order. 例如,最好使用 little endian 平台(如 Intel 计算机)上的 little endian 字节顺序。For example, it is better to use the little endian byte order on little endian platforms, such as Intel computers.

GetPreamble方法检索包含字节顺序标记(BOM)的字节数组。The GetPreamble method retrieves an array of bytes that includes the byte order mark (BOM). 如果此字节数组的前缀为编码的流,则它有助于解码器识别所使用的编码格式。If this byte array is prefixed to an encoded stream, it helps the decoder to identify the encoding format used.

有关字节顺序和字节顺序标记的详细信息,请参阅unicode 主页上的 unicode 标准。For more information on byte order and the byte order mark, see The Unicode Standard at the Unicode home page.

请注意,编码类允许错误:Note that the encoding classes allow errors to:

  • 以无提示方式更改为 "?" 字符。Silently change to a "?" character.

  • 使用 "最佳匹配" 字符。Use a "best fit" character.

  • 通过将EncoderFallback和类与 U + FFFD Unicode 替换字符一起DecoderFallback使用,更改为应用程序特定的行为。Change to an application-specific behavior through use of the EncoderFallback and DecoderFallback classes with the U+FFFD Unicode replacement character.

应在出现任何数据流错误时引发异常。You should throw an exception on any data stream error. 应用在适用或使用EncoderExceptionFallback和类时, DecoderExceptionFallback使用 "throwonerror" 标志。An app either uses a "throwonerror" flag when applicable or uses the EncoderExceptionFallback and DecoderExceptionFallback classes. 通常不建议使用最佳回退,因为这可能会导致数据丢失或混乱,并比简单字符替换慢。Best fit fallback is often not recommended because it can cause data loss or confusion and is slower than simple character replacements. 对于 ANSI 编码,最佳行为是默认值。For ANSI encodings, the best fit behavior is the default.

构造函数

Encoding() Encoding() Encoding() Encoding()

初始化 Encoding 类的新实例。Initializes a new instance of the Encoding class.

Encoding(Int32) Encoding(Int32) Encoding(Int32) Encoding(Int32)

初始化对应于指定代码页的 Encoding 类的新实例。Initializes a new instance of the Encoding class that corresponds to the specified code page.

Encoding(Int32, EncoderFallback, DecoderFallback) Encoding(Int32, EncoderFallback, DecoderFallback) Encoding(Int32, EncoderFallback, DecoderFallback) Encoding(Int32, EncoderFallback, DecoderFallback)

使用指定编码器和解码器回退策略初始化对应于指定代码页的 Encoding 类的新实例。Initializes a new instance of the Encoding class that corresponds to the specified code page with the specified encoder and decoder fallback strategies.

属性

ASCII ASCII ASCII ASCII

获取 ASCII(7 位)字符集的编码。Gets an encoding for the ASCII (7-bit) character set.

BigEndianUnicode BigEndianUnicode BigEndianUnicode BigEndianUnicode

获取使用 Big Endian 字节顺序的 UTF-16 格式的编码。Gets an encoding for the UTF-16 format that uses the big endian byte order.

BodyName BodyName BodyName BodyName

在派生类中重写时,获取可与邮件代理正文标记一起使用的当前编码的名称。When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags.

CodePage CodePage CodePage CodePage

在派生类中重写时,获取当前 Encoding 的代码页标识符。When overridden in a derived class, gets the code page identifier of the current Encoding.

DecoderFallback DecoderFallback DecoderFallback DecoderFallback

获取或设置当前 DecoderFallback 对象的 Encoding 对象。Gets or sets the DecoderFallback object for the current Encoding object.

Default Default Default Default

获取此 .NET 实现的默认编码。Gets the default encoding for this .NET implementation.

EncoderFallback EncoderFallback EncoderFallback EncoderFallback

获取或设置当前 EncoderFallback 对象的 Encoding 对象。Gets or sets the EncoderFallback object for the current Encoding object.

EncodingName EncodingName EncodingName EncodingName

在派生类中重写时,获取当前编码的用户可读说明。When overridden in a derived class, gets the human-readable description of the current encoding.

HeaderName HeaderName HeaderName HeaderName

在派生类中重写时,获取可与邮件代理头标记一起使用的当前编码的名称。When overridden in a derived class, gets a name for the current encoding that can be used with mail agent header tags.

IsBrowserDisplay IsBrowserDisplay IsBrowserDisplay IsBrowserDisplay

在派生类中重写时,获取一个值,该值指示浏览器客户端是否可以使用当前的编码显示内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for displaying content.

IsBrowserSave IsBrowserSave IsBrowserSave IsBrowserSave

在派生类中重写时,获取一个值,该值指示浏览器客户端是否可以使用当前的编码保存内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for saving content.

IsMailNewsDisplay IsMailNewsDisplay IsMailNewsDisplay IsMailNewsDisplay

在派生类中重写时,获取一个值,该值指示邮件和新闻客户端是否可以使用当前的编码显示内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.

IsMailNewsSave IsMailNewsSave IsMailNewsSave IsMailNewsSave

在派生类中重写时,获取一个值,该值指示邮件和新闻客户端是否可以使用当前的编码保存内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for saving content.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

在派生类中重写时,获取一个值,该值指示当前的编码是否为只读。When overridden in a derived class, gets a value indicating whether the current encoding is read-only.

IsSingleByte IsSingleByte IsSingleByte IsSingleByte

在派生类中重写时,获取一个值,该值指示当前的编码是否使用单字节码位。When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points.

Preamble Preamble Preamble Preamble
Unicode Unicode Unicode Unicode

获取使用 Little-Endian 字节顺序的 UTF-16 格式的编码。Gets an encoding for the UTF-16 format using the little endian byte order.

UTF32 UTF32 UTF32 UTF32

获取使用 Little-Endian 字节顺序的 UTF-32 格式的编码。Gets an encoding for the UTF-32 format using the little endian byte order.

UTF7 UTF7 UTF7 UTF7

获取 UTF-7 格式的编码。Gets an encoding for the UTF-7 format.

UTF8 UTF8 UTF8 UTF8

获取 UTF-8 格式的编码。Gets an encoding for the UTF-8 format.

WebName WebName WebName WebName

在派生类中重写时,获取在 Internet 编号分配管理机构 (IANA) 注册的当前编码的名称。When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.

WindowsCodePage WindowsCodePage WindowsCodePage WindowsCodePage

在派生类中重写时,获取与当前编码最紧密对应的 Windows 操作系统代码页。When overridden in a derived class, gets the Windows operating system code page that most closely corresponds to the current encoding.

方法

Clone() Clone() Clone() Clone()

当在派生类中重写时,创建当前 Encoding 对象的一个卷影副本。When overridden in a derived class, creates a shallow copy of the current Encoding object.

Convert(Encoding, Encoding, Byte[]) Convert(Encoding, Encoding, Byte[]) Convert(Encoding, Encoding, Byte[]) Convert(Encoding, Encoding, Byte[])

将整个字节数组从一种编码转换为另一种编码。Converts an entire byte array from one encoding to another.

Convert(Encoding, Encoding, Byte[], Int32, Int32) Convert(Encoding, Encoding, Byte[], Int32, Int32) Convert(Encoding, Encoding, Byte[], Int32, Int32) Convert(Encoding, Encoding, Byte[], Int32, Int32)

将字节数组内某个范围的字节从一种编码转换为另一种编码。Converts a range of bytes in a byte array from one encoding to another.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的 Object 是否等同于当前实例。Determines whether the specified Object is equal to the current instance.

GetByteCount(Char*, Int32) GetByteCount(Char*, Int32) GetByteCount(Char*, Int32) GetByteCount(Char*, Int32)

在派生类中重写时,计算对一组字符(从指定的字符指针处开始)进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer.

GetByteCount(Char[]) GetByteCount(Char[]) GetByteCount(Char[]) GetByteCount(Char[])

在派生类中重写时,计算对指定字符数组中的所有字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding all the characters in the specified character array.

GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32)

在派生类中重写时,计算对指定字符数组中的一组字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array.

GetByteCount(ReadOnlySpan<Char>) GetByteCount(ReadOnlySpan<Char>) GetByteCount(ReadOnlySpan<Char>) GetByteCount(ReadOnlySpan<Char>)
GetByteCount(String) GetByteCount(String) GetByteCount(String) GetByteCount(String)

在派生类中重写时,计算对指定字符串中的字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified string.

GetByteCount(String, Int32, Int32) GetByteCount(String, Int32, Int32) GetByteCount(String, Int32, Int32) GetByteCount(String, Int32, Int32)
GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32)

在派生类中重写时,将一组字符(从指定的字符指针开始)编码为一个字节序列,并从指定的字节指针开始存储该字节序列。When overridden in a derived class, encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer.

GetBytes(Char[]) GetBytes(Char[]) GetBytes(Char[]) GetBytes(Char[])

在派生类中重写时,将指定字符数组中的所有字符编码为一个字节序列。When overridden in a derived class, encodes all the characters in the specified character array into a sequence of bytes.

GetBytes(Char[], Int32, Int32) GetBytes(Char[], Int32, Int32) GetBytes(Char[], Int32, Int32) GetBytes(Char[], Int32, Int32)

在派生类中重写时,将指定字符数组中的一组字符编码为一个字节序列。When overridden in a derived class, encodes a set of characters from the specified character array into a sequence of bytes.

GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32)

在派生类中重写时,将指定字符数组中的一组字符编码为指定的字节数组。When overridden in a derived class, encodes a set of characters from the specified character array into the specified byte array.

GetBytes(ReadOnlySpan<Char>, Span<Byte>) GetBytes(ReadOnlySpan<Char>, Span<Byte>) GetBytes(ReadOnlySpan<Char>, Span<Byte>) GetBytes(ReadOnlySpan<Char>, Span<Byte>)
GetBytes(String) GetBytes(String) GetBytes(String) GetBytes(String)

在派生类中重写时,将指定字符串中的所有字符编码为一个字节序列。When overridden in a derived class, encodes all the characters in the specified string into a sequence of bytes.

GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32)
GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32)

在派生类中重写时,将指定字符串中的一组字符编码为指定的字节数组。When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array.

GetCharCount(Byte*, Int32) GetCharCount(Byte*, Int32) GetCharCount(Byte*, Int32) GetCharCount(Byte*, Int32)

在派生类中重写时,计算对字节序列(从指定的字节指针开始)进行解码所产生的字符数。When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.

GetCharCount(Byte[]) GetCharCount(Byte[]) GetCharCount(Byte[]) GetCharCount(Byte[])

在派生类中重写时,计算对指定字节数组中的所有字节进行解码所产生的字符数。When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array.

GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32)

在派生类中重写时,计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

GetCharCount(ReadOnlySpan<Byte>) GetCharCount(ReadOnlySpan<Byte>) GetCharCount(ReadOnlySpan<Byte>) GetCharCount(ReadOnlySpan<Byte>)
GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32)

在派生类中重写时,将一个字节序列(从指定的字节指针开始)解码为一组字符,并从指定的字符指针开始存储该组字符。When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer.

GetChars(Byte[]) GetChars(Byte[]) GetChars(Byte[]) GetChars(Byte[])

在派生类中重写时,将指定字节数组中的所有字节解码为一组字符。When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters.

GetChars(Byte[], Int32, Int32) GetChars(Byte[], Int32, Int32) GetChars(Byte[], Int32, Int32) GetChars(Byte[], Int32, Int32)

在派生类中重写时,将指定字节数组中的一个字节序列解码为一组字符。When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters.

GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32)

在派生类中重写时,将指定字节数组中的字节序列解码为指定的字符数组。When overridden in a derived class, decodes a sequence of bytes from the specified byte array into the specified character array.

GetChars(ReadOnlySpan<Byte>, Span<Char>) GetChars(ReadOnlySpan<Byte>, Span<Char>) GetChars(ReadOnlySpan<Byte>, Span<Char>) GetChars(ReadOnlySpan<Byte>, Span<Char>)
GetDecoder() GetDecoder() GetDecoder() GetDecoder()

在派生类中重写时,获取一个解码器,该解码器将已编码的字节序列转换为字符序列。When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into a sequence of characters.

GetEncoder() GetEncoder() GetEncoder() GetEncoder()

在派生类中重写时,获取一个解码器,该解码器将 Unicode 字符序列转换为已编码的字节序列。When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters into an encoded sequence of bytes.

GetEncoding(Int32) GetEncoding(Int32) GetEncoding(Int32) GetEncoding(Int32)

返回与指定代码页标识符关联的编码。Returns the encoding associated with the specified code page identifier.

GetEncoding(Int32, EncoderFallback, DecoderFallback) GetEncoding(Int32, EncoderFallback, DecoderFallback) GetEncoding(Int32, EncoderFallback, DecoderFallback) GetEncoding(Int32, EncoderFallback, DecoderFallback)

返回与指定代码页标识符关联的编码。Returns the encoding associated with the specified code page identifier. 参数指定一个错误处理程序,用于处理无法编码的字符和无法解码的字节序列。Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

GetEncoding(String) GetEncoding(String) GetEncoding(String) GetEncoding(String)

返回与指定代码页名称关联的编码。Returns the encoding associated with the specified code page name.

GetEncoding(String, EncoderFallback, DecoderFallback) GetEncoding(String, EncoderFallback, DecoderFallback) GetEncoding(String, EncoderFallback, DecoderFallback) GetEncoding(String, EncoderFallback, DecoderFallback)

返回与指定代码页名称关联的编码。Returns the encoding associated with the specified code page name. 参数指定一个错误处理程序,用于处理无法编码的字符和无法解码的字节序列。Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

GetEncodings() GetEncodings() GetEncodings() GetEncodings()

返回包含所有编码的数组。Returns an array that contains all encodings.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回当前实例的哈希代码。Returns the hash code for the current instance.

GetMaxByteCount(Int32) GetMaxByteCount(Int32) GetMaxByteCount(Int32) GetMaxByteCount(Int32)

在派生类中重写时,计算对指定数目的字符进行编码所产生的最大字节数。When overridden in a derived class, calculates the maximum number of bytes produced by encoding the specified number of characters.

GetMaxCharCount(Int32) GetMaxCharCount(Int32) GetMaxCharCount(Int32) GetMaxCharCount(Int32)

在派生类中重写时,计算对指定数目的字节进行解码时所产生的最大字符数。When overridden in a derived class, calculates the maximum number of characters produced by decoding the specified number of bytes.

GetPreamble() GetPreamble() GetPreamble() GetPreamble()

在派生类中重写时,返回指定所用编码的字节序列。When overridden in a derived class, returns a sequence of bytes that specifies the encoding used.

GetString(Byte*, Int32) GetString(Byte*, Int32) GetString(Byte*, Int32) GetString(Byte*, Int32)

在派生类中重写时,将在指定地址开始的指定字节数解码为字符串。When overridden in a derived class, decodes a specified number of bytes starting at a specified address into a string.

GetString(Byte[]) GetString(Byte[]) GetString(Byte[]) GetString(Byte[])

在派生类中重写时,将指定字节数组中的所有字节解码为一个字符串。When overridden in a derived class, decodes all the bytes in the specified byte array into a string.

GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32)

在派生类中重写时,将指定字节数组中的一个字节序列解码为一个字符串。When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a string.

GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsAlwaysNormalized() IsAlwaysNormalized() IsAlwaysNormalized() IsAlwaysNormalized()

使用默认范式获取一个值,该值指示当前编码是否始终被规范化。Gets a value indicating whether the current encoding is always normalized, using the default normalization form.

IsAlwaysNormalized(NormalizationForm) IsAlwaysNormalized(NormalizationForm) IsAlwaysNormalized(NormalizationForm) IsAlwaysNormalized(NormalizationForm)

在派生类中重写时,使用指定范式获取一个值,该值指示当前编码是否始终被规范化。When overridden in a derived class, gets a value indicating whether the current encoding is always normalized, using the specified normalization form.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
RegisterProvider(EncodingProvider) RegisterProvider(EncodingProvider) RegisterProvider(EncodingProvider) RegisterProvider(EncodingProvider)

注册编码提供程序。Registers an encoding provider.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于

另请参阅