UTF8Encoding UTF8Encoding UTF8Encoding UTF8Encoding Class

定義

代表 Unicode 字元的 UTF-8 編碼方式。Represents a UTF-8 encoding of Unicode characters.

public ref class UTF8Encoding : System::Text::Encoding
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class UTF8Encoding : System.Text.Encoding
type UTF8Encoding = class
    inherit Encoding
Public Class UTF8Encoding
Inherits Encoding
繼承
UTF8EncodingUTF8EncodingUTF8EncodingUTF8Encoding
屬性

範例

下列範例會使用UTF8Encoding物件來編碼 Unicode 字元的字串, 並將其儲存在位元組陣列中。The following example uses a UTF8Encoding object to encode a string of Unicode characters and store them in a byte array. Unicode 字串包含 ASCII 字元範圍外的兩個字元, Pi (U + 03A0) 和 Sigma (U + 03A3)。The Unicode string includes two characters, Pi (U+03A0) and Sigma (U+03A3), that are outside the ASCII character range. 當編碼的位元組陣列解碼回字串時, Pi 和 Sigma 字元仍會存在。When the encoded byte array is decoded back to a string, the Pi and Sigma characters are still present.

using namespace System;
using namespace System::Text;
//using namespace System::Collections;

int main()
{
   // Create a UTF-8 encoding.
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   
   // A Unicode string with two characters outside an 8-bit code range.
   String^ unicodeString = L"This Unicode string has 2 characters " +
                           L"outside the ASCII range:\n" +
                           L"Pi (\u03a0), and Sigma (\u03a3).";
   Console::WriteLine("Original string:");
   Console::WriteLine(unicodeString);
   
   // Encode the string.
   array<Byte>^ encodedBytes = utf8->GetBytes(unicodeString );
   Console::WriteLine();
   Console::WriteLine("Encoded bytes:");
   for (int ctr = 0; ctr < encodedBytes->Length; ctr++) {
      Console::Write( "{0:X2} ", encodedBytes[ctr]);
      if ((ctr + 1) % 25 == 0)
         Console::WriteLine();
   }

   Console::WriteLine();
   
   // Decode bytes back to string.
   String^ decodedString = utf8->GetString(encodedBytes);
   Console::WriteLine();
   Console::WriteLine("Decoded bytes:");
   Console::WriteLine(decodedString);
}
// The example displays the following output:
//    Original string:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    Encoded bytes:
//    54 68 69 73 20 55 6E 69 63 6F 64 65 20 73 74 72 69 6E 67 20 68 61 73 20 32
//    20 63 68 61 72 61 63 74 65 72 73 20 6F 75 74 73 69 64 65 20 74 68 65 20 41
//    53 43 49 49 20 72 61 6E 67 65 3A 20 0D 0A 50 69 20 28 CE A0 29 2C 20 61 6E
//    64 20 53 69 67 6D 61 20 28 CE A3 29 2E
//
//    Decoded bytes:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
using System;
using System.Text;

class Example
{
    public static void Main()
    {
        // Create a UTF-8 encoding.
        UTF8Encoding utf8 = new UTF8Encoding();
        
        // A Unicode string with two characters outside an 8-bit code range.
        String unicodeString =
            "This Unicode string has 2 characters outside the " +
            "ASCII range:\n" +
            "Pi (\u03a0), and Sigma (\u03a3).";
        Console.WriteLine("Original string:");
        Console.WriteLine(unicodeString);

        // Encode the string.
        Byte[] encodedBytes = utf8.GetBytes(unicodeString);
        Console.WriteLine();
        Console.WriteLine("Encoded bytes:");
        for (int ctr = 0; ctr < encodedBytes.Length; ctr++) {
            Console.Write("{0:X2} ", encodedBytes[ctr]);
            if ((ctr + 1) %  25 == 0)
               Console.WriteLine();
        }
        Console.WriteLine();
        
        // Decode bytes back to string.
        String decodedString = utf8.GetString(encodedBytes);
        Console.WriteLine();
        Console.WriteLine("Decoded bytes:");
        Console.WriteLine(decodedString);
    }
}
// The example displays the following output:
//    Original string:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    Encoded bytes:
//    54 68 69 73 20 55 6E 69 63 6F 64 65 20 73 74 72 69 6E 67 20 68 61 73 20 32
//    20 63 68 61 72 61 63 74 65 72 73 20 6F 75 74 73 69 64 65 20 74 68 65 20 41
//    53 43 49 49 20 72 61 6E 67 65 3A 20 0D 0A 50 69 20 28 CE A0 29 2C 20 61 6E
//    64 20 53 69 67 6D 61 20 28 CE A3 29 2E
//
//    Decoded bytes:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
Imports System.Text

Class Example
    Public Shared Sub Main()
        ' Create a UTF-8 encoding.
        Dim utf8 As New UTF8Encoding()
        
        ' A Unicode string with two characters outside an 8-bit code range.
        Dim unicodeString As String = _
            "This Unicode string has 2 characters outside the " &
            "ASCII range: " & vbCrLf &
            "Pi (" & ChrW(&h03A0) & "), and Sigma (" & ChrW(&h03A3) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(unicodeString)
        
        ' Encode the string.
        Dim encodedBytes As Byte() = utf8.GetBytes(unicodeString)
        Console.WriteLine()
        Console.WriteLine("Encoded bytes:")
        For ctr As Integer = 0 To encodedBytes.Length - 1
            Console.Write("{0:X2} ", encodedBytes(ctr))
            If (ctr + 1) Mod 25 = 0 Then Console.WriteLine
        Next
        Console.WriteLine()
        
        ' Decode bytes back to string.
        Dim decodedString As String = utf8.GetString(encodedBytes)
        Console.WriteLine()
        Console.WriteLine("Decoded bytes:")
        Console.WriteLine(decodedString)
    End Sub
End Class
' The example displays the following output:
'    Original string:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    Encoded bytes:
'    54 68 69 73 20 55 6E 69 63 6F 64 65 20 73 74 72 69 6E 67 20 68 61 73 20 32
'    20 63 68 61 72 61 63 74 65 72 73 20 6F 75 74 73 69 64 65 20 74 68 65 20 41
'    53 43 49 49 20 72 61 6E 67 65 3A 20 0D 0A 50 69 20 28 CE A0 29 2C 20 61 6E
'    64 20 53 69 67 6D 61 20 28 CE A3 29 2E
'
'    Decoded bytes:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).

下列範例會使用與上一個範例相同的字串, 不同之處在于它會將編碼的位元組寫入檔案, 並使用位元組順序標記 (BOM) 在位元組資料流程前面加上首碼。The following example uses the same string as the previous example, except that it writes the encoded bytes to a file and prefixes the byte stream with a byte order mark (BOM). 然後它會以兩種不同的方式讀取檔案: 使用StreamReader物件做為文字檔, 以及當做二進位檔案。It then reads the file in two different ways: as a text file by using a StreamReader object; and as a binary file. 如您所預期, 新讀取的字串都不包含 BOM。As you would expect, neither newly-read string includes the BOM.

using System;
using System.IO;
using System.Text;

public class Example
{
   public static void Main()
   {
        // Create a UTF-8 encoding that supports a BOM.
        Encoding utf8 = new UTF8Encoding(true);

        // A Unicode string with two characters outside an 8-bit code range.
        String unicodeString =
            "This Unicode string has 2 characters outside the " +
            "ASCII range:\n" +
            "Pi (\u03A0)), and Sigma (\u03A3).";
        Console.WriteLine("Original string:");
        Console.WriteLine(unicodeString);
        Console.WriteLine();

        // Encode the string.
        Byte[] encodedBytes = utf8.GetBytes(unicodeString);
        Console.WriteLine("The encoded string has {0} bytes.",
                          encodedBytes.Length);
        Console.WriteLine();

        // Write the bytes to a file with a BOM.
        var fs = new FileStream(@".\UTF8Encoding.txt", FileMode.Create);
        Byte[] bom = utf8.GetPreamble();
        fs.Write(bom, 0, bom.Length);
        fs.Write(encodedBytes, 0, encodedBytes.Length);
        Console.WriteLine("Wrote {0} bytes to the file.", fs.Length);
        fs.Close();
        Console.WriteLine();

        // Open the file using StreamReader.
        var sr = new StreamReader(@".\UTF8Encoding.txt");
        String newString = sr.ReadToEnd();
        sr.Close();
        Console.WriteLine("String read using StreamReader:");
        Console.WriteLine(newString);
        Console.WriteLine();

        // Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(@".\UTF8Encoding.txt", FileMode.Open);
        Byte[] bytes = new Byte[fs.Length];
        fs.Read(bytes, 0, (int)fs.Length);
        fs.Close();

        String decodedString = utf8.GetString(bytes);
        Console.WriteLine("Decoded bytes:");
        Console.WriteLine(decodedString);
   }
}
// The example displays the following output:
//    Original string:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    The encoded string has 88 bytes.
//
//    Wrote 91 bytes to the file.
//
//    String read using StreamReader:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    Decoded bytes:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
Imports System.IO
Imports System.Text

Class Example
    Public Shared Sub Main()
        ' Create a UTF-8 encoding that supports a BOM.
        Dim utf8 As New UTF8Encoding(True)
        
        ' A Unicode string with two characters outside an 8-bit code range.
        Dim unicodeString As String = _
            "This Unicode string has 2 characters outside the " &
            "ASCII range: " & vbCrLf &
            "Pi (" & ChrW(&h03A0) & "), and Sigma (" & ChrW(&h03A3) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(unicodeString)
        Console.WriteLine()
        
        ' Encode the string.
        Dim encodedBytes As Byte() = utf8.GetBytes(unicodeString)
        Console.WriteLine("The encoded string has {0} bytes.",
                          encodedBytes.Length)
        Console.WriteLine()
        
        ' Write the bytes to a file with a BOM.
        Dim fs As New FileStream(".\UTF8Encoding.txt", FileMode.Create)
        Dim bom() As Byte = utf8.GetPreamble()
        fs.Write(bom, 0, bom.Length)
        fs.Write(encodedBytes, 0, encodedBytes.Length)
        Console.WriteLine("Wrote {0} bytes to the file.", fs.Length)
        fs.Close()
        Console.WriteLine()
        
        ' Open the file using StreamReader.
        Dim sr As New StreamReader(".\UTF8Encoding.txt")
        Dim newString As String = sr.ReadToEnd()
        sr.Close()
        Console.WriteLine("String read using StreamReader:")
        Console.WriteLine(newString)
        Console.WriteLine()
        
        ' Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(".\UTF8Encoding.txt", FileMode.Open)
        Dim bytes(fs.Length - 1) As Byte
        fs.Read(bytes, 0, fs.Length)
        fs.Close()

        Dim decodedString As String = utf8.GetString(bytes)
        Console.WriteLine("Decoded bytes:")
        Console.WriteLine(decodedString)
    End Sub
End Class
' The example displays the following output:
'    Original string:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    The encoded string has 88 bytes.
'
'    Wrote 91 bytes to the file.
'
'    String read using StreamReader:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    Decoded bytes:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).

備註

編碼是將一組 Unicode 字元轉換成位元組序列的處理程序。Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. 解碼是將編碼的位元組序列轉換成一組 Unicode 字元的過程。Decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters.

UTF-8 是一種 Unicode 編碼方式, 以一到四個位元組的序列來表示每個程式碼點。UTF-8 is a Unicode encoding that represents each code point as a sequence of one to four bytes. 不同于 UTF-16 和 UTF-32 編碼, UTF-8 編碼不需要 "endian";無論處理器是以大到小或不是以位元組為限, 都是相同的編碼配置。Unlike the UTF-16 and UTF-32 encodings, the UTF-8 encoding does not require "endianness"; the encoding scheme is the same regardless of whether the processor is big-endian or little-endian. UTF8Encoding對應至 Windows 字碼頁65001。UTF8Encoding corresponds to the Windows code page 65001. 如需所支援System.Text之 UTFs 和其他編碼的詳細資訊, 請參閱.NET Framework 中的字元編碼For more information about the UTFs and other encodings supported by System.Text, see Character Encoding in the .NET Framework.

您可以透過數UTF8Encoding種方式來具現化物件, 取決於您是否想要提供位元組順序標記 (BOM), 以及是否要啟用錯誤偵測。You can instantiate a UTF8Encoding object in a number of ways, depending on whether you want to it to provide a byte order mark (BOM) and whether you want to enable error detection. 下表列出會Encoding UTF8Encoding傳回物件的函數和屬性。The following table lists the constructors and the Encoding property that return a UTF8Encoding object.

成員Member BOMBOM 錯誤偵測Error detection
Encoding.UTF8 Yes 否 (取代回復)No (Replacement fallback)
UTF8Encoding.UTF8Encoding() No 否 (取代回復)No (Replacement fallback)
UTF8Encoding.UTF8Encoding(Boolean) 可設定Configurable 否 (取代回復)No (Replacement fallback)
UTF8Encoding.UTF8Encoding(Boolean, Boolean) 可設定Configurable 可設定Configurable

方法會判斷有多少位元組會導致編碼一組 Unicode 字元, 而方法則GetBytes會執行實際的編碼。 GetByteCountThe GetByteCount method determines how many bytes result in encoding a set of Unicode characters, and the GetBytes method performs the actual encoding.

同樣地, GetCharCount方法會決定有多少字元會導致解碼位元組序列, GetChars而和GetString方法則會執行實際解碼。Likewise, the GetCharCount method determines how many characters result in decoding a sequence of bytes, and the GetChars and GetString methods perform the actual decoding.

針對能夠在編碼或解碼跨越多個區塊的資料時 (例如, 以100000個字元區段編碼之1000000字元的字串) 來儲存狀態資訊的編碼器或解碼器, 請使用GetEncoderGetDecoder屬性。各自.For an encoder or decoder that is able to save state information when encoding or decoding data that spans multiple blocks (such as string of 1 million characters that is encoded in 100,000-character segments), use the GetEncoder and GetDecoder properties, respectively.

(選擇性) 物件會提供位元組順序標記 (BOM), 這是一種位元組陣列, 可以在編碼程式所產生的位元組資料流程開頭前面加上前置詞。 UTF8EncodingOptionally, the UTF8Encoding object provides a byte order mark (BOM), which is an array of bytes that can be prefixed to the beginning of the byte stream that results from the encoding process. 如果 UTF-8 編碼的位元組資料流程前面加上位順序標記 (BOM), 它會協助此解碼器判斷位元組順序和轉換格式或 UTF。If a UTF-8 encoded byte stream is prefaced with a byte order mark (BOM), it helps the decoder determine the byte order and the transformation format or UTF. 不過要注意的是, Unicode 標準不需要也不建議使用 UTF-8 編碼資料流程中的 BOM。Note, however, that the Unicode Standard neither requires nor recommends a BOM in UTF-8 encoded streams. 如需位元組順序和位元組順序標記的詳細資訊, 請參閱unicode 首頁的 unicode 標準。For more information on byte order and the byte order mark, see The Unicode Standard at the Unicode home page.

如果編碼器設定為提供 BOM, 您可以藉由呼叫GetPreamble方法來抓取它, 否則方法會傳回空陣列。If the encoder is configured to provide a BOM, you can retrieve it by calling the GetPreamble method; otherwise, the method returns an empty array. 請注意, 即使UTF8Encoding已針對 bom 支援設定物件, 您也必須視需要在編碼的位元組資料流程開頭包含 BOM; UTF8Encoding類別的編碼方法不會自動執行此動作。Note that, even if a UTF8Encoding object is configured for BOM support, you must include the BOM at the beginning of the encoded byte stream as appropriate; the encoding methods of the UTF8Encoding class do not do this automatically.

警告

若要啟用錯誤偵測並讓類別實例更安全, 您應該呼叫此UTF8Encoding(Boolean, Boolean)函式, 並throwOnInvalidBytes將參數設定true為。To enable error detection and to make the class instance more secure, you should call the UTF8Encoding(Boolean, Boolean) constructor and set the throwOnInvalidBytes parameter to true. 啟用錯誤偵測之後, 偵測到無效字元或位元組ArgumentException序列的方法會擲回例外狀況。With error detection enabled, a method that detects an invalid sequence of characters or bytes throws an ArgumentException exception. 如果沒有錯誤偵測, 則不會擲回例外狀況, 而且通常會忽略不正確序列。Without error detection, no exception is thrown, and the invalid sequence is generally ignored.

注意

如果物件已使用不同的 .NET Framework 版本進行序列化和還原序列化, 則不會保留 UTF-8 編碼物件的狀態。The state of a UTF-8 encoded object is not preserved if the object is serialized and deserialized using different .NET Framework versions.

建構函式

UTF8Encoding() UTF8Encoding() UTF8Encoding() UTF8Encoding()

初始化 UTF8Encoding 類別的新執行個體。Initializes a new instance of the UTF8Encoding class.

UTF8Encoding(Boolean) UTF8Encoding(Boolean) UTF8Encoding(Boolean) UTF8Encoding(Boolean)

初始化 UTF8Encoding 類別的新執行個體。Initializes a new instance of the UTF8Encoding class. 參數會指定是否提供 Unicode 位元組順序標記。A parameter specifies whether to provide a Unicode byte order mark.

UTF8Encoding(Boolean, Boolean) UTF8Encoding(Boolean, Boolean) UTF8Encoding(Boolean, Boolean) UTF8Encoding(Boolean, Boolean)

初始化 UTF8Encoding 類別的新執行個體。Initializes a new instance of the UTF8Encoding class. 參數會指定是否提供 Unicode 位元組順序標記,以及是否在偵測到無效的編碼方式時擲回例外狀況。Parameters specify whether to provide a Unicode byte order mark and whether to throw an exception when an invalid encoding is detected.

屬性

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.

(Inherited from Encoding)
CodePage CodePage CodePage CodePage

在衍生類別中覆寫時,取得目前 Encoding 的字碼頁識別項。When overridden in a derived class, gets the code page identifier of the current Encoding.

(Inherited from Encoding)
DecoderFallback DecoderFallback DecoderFallback DecoderFallback

取得或設定目前 DecoderFallback 物件的 Encoding 物件。Gets or sets the DecoderFallback object for the current Encoding object.

(Inherited from Encoding)
EncoderFallback EncoderFallback EncoderFallback EncoderFallback

取得或設定目前 EncoderFallback 物件的 Encoding 物件。Gets or sets the EncoderFallback object for the current Encoding object.

(Inherited from Encoding)
EncodingName EncodingName EncodingName EncodingName

在衍生類別中覆寫時,取得目前編碼方式的人們可讀取 (Human-Readable) 的描述。When overridden in a derived class, gets the human-readable description of the current encoding.

(Inherited from 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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

在衍生類別中覆寫時,取得值,指出目前的編碼方式是否為唯讀。When overridden in a derived class, gets a value indicating whether the current encoding is read-only.

(Inherited from Encoding)
IsSingleByte IsSingleByte IsSingleByte IsSingleByte

在衍生類別中覆寫時,取得值,指出目前的編碼方式是否使用單一位元組字碼指標。When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points.

(Inherited from Encoding)
Preamble Preamble Preamble Preamble

取得以 UTF-8 格式編碼的 Unicode 位元組順序標記 (若物件已設定為提供此項目)。Gets a Unicode byte order mark encoded in UTF-8 format, if this object is configured to supply one.

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.

(Inherited from 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.

(Inherited from Encoding)

方法

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

在衍生類別中覆寫時,會建立目前 Encoding 物件的淺層複本。When overridden in a derived class, creates a shallow copy of the current Encoding object.

(Inherited from Encoding)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的 UTF8Encoding 物件。Determines whether the specified object is equal to the current UTF8Encoding object.

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

計算將起始於指定字元指標的一組字元編碼所產生的位元組數目。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.

(Inherited from Encoding)
GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32) GetByteCount(Char[], Int32, Int32)

計算將指定字元陣列中的一組字元編碼所產生的位元組數目。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>)

計算將指定字元範圍編碼所產生的位元組數目。Calculates the number of bytes produced by encoding the specified character span.

GetByteCount(String) GetByteCount(String) GetByteCount(String) GetByteCount(String)

計算將指定 String 中的字元編碼所產生的位元組數目。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) Inherited from Encoding
GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32) GetBytes(Char*, Int32, Byte*, Int32)

將起始於指定字元指標的一組字元編碼成位元組序列;儲存該位元組序列時,係以指定的位元組指標為起始點。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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32) GetBytes(Char[], Int32, Int32, Byte[], Int32)

將指定字元陣列中的一組字元編碼成指定的位元組陣列。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>)

將指定的字元範圍編碼為指定的位元組範圍。Encodes the specified character span into the specified byte span.

GetBytes(String) GetBytes(String) GetBytes(String) GetBytes(String)

將指定 String 物件中的字元編碼成位元組序列。Encodes the characters in a specified String object into a sequence of bytes.

GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32) GetBytes(String, Int32, Int32) Inherited from Encoding
GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32) GetBytes(String, Int32, Int32, Byte[], Int32)

將指定 String 中的一組字元編碼成指定的位元組陣列。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)

計算將起始於指定位元組指標的位元組序列解碼所產生的字元數。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.

(Inherited from Encoding)
GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32) GetCharCount(Byte[], Int32, Int32)

計算將指定位元組陣列中的位元組序列解碼所產生的字元數。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>)

計算解碼指定位元組範圍所產生的字元數目。Calculates the number of characters produced by decoding the specified byte span.

GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32) GetChars(Byte*, Int32, Char*, Int32)

將起始於指定位元組指標的位元組序列解碼成一組字元;儲存該組字元時,係以指定的字元指標為起始點。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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32) GetChars(Byte[], Int32, Int32, Char[], Int32)

將指定位元組陣列中的位元組序列解碼成指定的字元陣列。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>)

將指定的位元組範圍解碼為指定的字元範圍。Decodes the specified byte span into the specified character span.

GetDecoder() GetDecoder() GetDecoder() GetDecoder()

取得可以將以 UTF-8 編碼的位元組序列轉換成 Unicode 字元序列的解碼器。Obtains a decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters.

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

取得可以將 Unicode 字元序列轉換成以 UTF-8 編碼的位元組序列的編碼器。Obtains an encoder that converts a sequence of Unicode characters into a UTF-8 encoded sequence of bytes.

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

傳回目前執行個體的雜湊碼。Returns the hash code for the current instance.

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

計算將指定數目的字元編碼所產生的最大位元組數目。Calculates the maximum number of bytes produced by encoding the specified number of characters.

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

計算將指定數目的位元組解碼所產生的最大字元數。Calculates the maximum number of characters produced by decoding the specified number of bytes.

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

如果設定 UTF8Encoding 編碼物件提供編碼方式,則會傳回以 UTF-8 格式編碼的 Unicode 位元組順序標記。Returns a Unicode byte order mark encoded in UTF-8 format, if the UTF8Encoding encoding object is configured to supply one.

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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32) GetString(Byte[], Int32, Int32)

將位元組陣列中的某一段位元組範圍解碼成字串。Decodes a range of bytes from a byte array into a string.

GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>) GetString(ReadOnlySpan<Byte>) Inherited from Encoding
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.

(Inherited from Encoding)
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.

(Inherited from Encoding)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱