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. 如果您必須將任意二進位資料編碼成文字,您應該使用像是的方法Convert.ToBase64CharArray所實作為 uuencode 的通訊協定,例如。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. 同時支援小數位序和大時數位的位元組順序。Both little endian and big endian byte orders are supported. 也可以透過Unicode屬性BigEndianUnicode和屬性取得。Also available through the Unicode property and the BigEndianUnicode property.

  • UTF32Encoding使用 UTF-32 編碼來編碼 Unicode 字元。UTF32Encoding encodes Unicode characters using the UTF-32 encoding. 同時支援小 endian (字碼頁12000)和 big 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 名稱Name 顯示名稱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 (大 endian)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-mac-羅馬尼亞文x-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-32 Big endian)Unicode (UTF-32 Big endian)
2000020000 x-中文-CNx-Chinese-CNS 繁體中文(CN)Chinese Traditional (CNS)
2000120001 x-cp20001x-cp20001 TCA 臺灣TCA Taiwan
2000220002 x-繁體中文-倚天x-Chinese-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-R-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 韓文 Korean-wansung-unicodeKorean Wansung
2102521025 cp1025cp1025 IBM EBCDIC (斯拉夫塞爾維亞文-保加利亞文)IBM EBCDIC (Cyrillic Serbian-Bulgarian)
2186621866 koi8-r-ukoi8-u 斯拉夫文(KOI8-R-U)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 EuropaEuropa
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

如果要轉換的資料僅適用于連續區塊(例如從資料流程讀取的資料),或如果資料量太大而需要分割成較小的區塊,您應該使用Decoder Encoder或由GetDecoder方法或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 和 UTF-32 編碼器可以使用位元組由大到小的位元組順序(第一個最重要的位元組)或位元組由小到大的位元組順序(第一個最不重要的位元組)。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 位元組由大到小的順序:00 41UTF-16 big endian byte order: 00 41

  • UTF-16 位元組由大到小的順序:41 00UTF-16 little endian byte order: 41 00

  • UTF-32 big endian 位元組順序:00 00 00 41UTF-32 big endian byte order: 00 00 00 41

  • UTF-32 位元組由小到大的位元組順序: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. 例如,最好是在極小 endian 的平臺(例如 Intel 電腦)上使用位元組由小到大的位元組順序。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.

  • 透過使用EncoderFallbackDecoderFallback類別搭配 U + FFFD Unicode 取代字元,變更為應用程式特有的行為。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. 應用程式會在適用時使用 "throwonerror" 旗標EncoderExceptionFallback ,或使用和DecoderExceptionFallback類別。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 位元) 字元集 (Character Set) 的編碼方式。Gets an encoding for the ASCII (7-bit) character set.

BigEndianUnicode BigEndianUnicode BigEndianUnicode BigEndianUnicode

取得 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

在衍生類別中覆寫時,取得目前編碼方式的人們可讀取 (Human-Readable) 的描述。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

以位元組由小到大位元組順序取得 UTF-16 格式的編碼方式。Gets an encoding for the UTF-16 format using the little endian byte order.

UTF32 UTF32 UTF32 UTF32

以位元組由小到大位元組順序取得 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 Assigned Numbers Authority (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 的淺層複本 (Shallow Copy)。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)

適用於

另請參閱