UTF8Encoding 類別

定義

代表 Unicode 字元的 UTF-8 編碼方式。

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

範例

下列範例會使用 UTF8Encoding 物件來編碼 Unicode 字元的字串,並將其儲存在位元組陣列中。 Unicode 字串包含兩個字元:Pi (U+03A0) 和 Sigma (U+03A3) ,這些字元超出 ASCII 字元範圍。 當編碼的位元組陣列解碼回字串時,Pi 和 Sigma 字元仍然存在。

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) 。 然後,它會以兩種不同的方式讀取檔案:使用 StreamReader 物件作為文字檔,以及做為二進位檔案。 如您所預期,新讀取的字串都未包含 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 字元轉換成位元組序列的處理程序。 解碼是將編碼位元組序列轉換成一組 Unicode 字元的程式。

UTF-8 是 Unicode 編碼,會將每個字碼點表示為一到四個位元組的序列。 不同于 UTF-16 和 UTF-32 編碼,UTF-8 編碼不需要「endianness」 ;編碼配置是相同的,不論處理器是大端還是小端。 UTF8Encoding 會對應至 Windows 字碼頁 65001。 如需 UTF 和支援之其他編碼 System.Text 的詳細資訊,請參閱.NET Framework中的字元編碼

您可以透過數種方式將 物件具現化 UTF8Encoding ,視您是否要提供位元組順序標記 (BOM) 以及是否要啟用錯誤偵測而定。 下表列出傳回 UTF8Encoding 物件的建構函式和 Encoding 屬性。

成員 BOM 錯誤偵測
Encoding.UTF8 沒有 (取代後援)
UTF8Encoding.UTF8Encoding() 沒有 (取代後援)
UTF8Encoding.UTF8Encoding(Boolean) 可設定 沒有 (取代後援)
UTF8Encoding.UTF8Encoding(Boolean, Boolean) 可設定 可設定

方法 GetByteCount 會決定一組 Unicode 字元編碼所產生的位元組數目,而 GetBytes 方法會執行實際的編碼。

同樣地, GetCharCount 方法會決定解碼一連串位元組的字元數,而 GetCharsGetString 方法會執行實際的解碼。

如果編碼器或解碼器能夠在編碼或解碼跨越多個區塊的資料時儲存狀態資訊, (例如以 100,000 個字元區段) 編碼的 1 百萬個字元字串,請分別使用 GetEncoderGetDecoder 屬性。

或者, UTF8Encoding 物件會提供位元組順序標記 (BOM) ,這是位元組陣列,可以前置至編碼程式所產生的位元組資料流程開頭。 如果 UTF-8 編碼的位元組資料流程前面加上位元組順序標記 (BOM) ,它可協助解碼器判斷位元組順序和轉換格式或 UTF。 不過請注意,Unicode 標準不需要也不建議 UTF-8 編碼資料流程中的 BOM。 如需位元組順序和位元組順序標記的詳細資訊,請參閱 Unicode 首頁上的 Unicode標準。

如果編碼器設定為提供 BOM,您可以藉由呼叫 GetPreamble 方法來擷取它,否則方法會傳回空陣列。 請注意,即使 UTF8Encoding 物件已設定為 BOM 支援,您也必須適當地在編碼位元組資料流程的開頭包含 BOM;類別的 UTF8Encoding 編碼方法不會自動執行此動作。

注意

若要啟用錯誤偵測,並讓類別實例更安全,您應該呼叫建構函式, UTF8Encoding(Boolean, Boolean) 並將 參數設定 throwOnInvalidBytestrue 。 啟用錯誤偵測後,偵測無效字元或位元組序列的方法會 ArgumentException 擲回例外狀況。 如果沒有錯誤偵測,就不會擲回任何例外狀況,而且通常會忽略不正確序列。

注意

如果使用不同的.NET Framework版本序列化和還原序列化物件,則不會保留 UTF-8 編碼物件的狀態。

建構函式

UTF8Encoding()

初始化 UTF8Encoding 類別的新執行個體。

UTF8Encoding(Boolean)

初始化 UTF8Encoding 類別的新執行個體。 參數會指定是否提供 Unicode 位元組順序標記。

UTF8Encoding(Boolean, Boolean)

初始化 UTF8Encoding 類別的新執行個體。 參數會指定是否提供 Unicode 位元組順序標記,以及是否在偵測到無效的編碼方式時擲回例外狀況。

屬性

BodyName

在衍生類別中覆寫時,取得可以與郵件代理程式主體標籤一起使用的目前編碼方式名稱。

(繼承來源 Encoding)
CodePage

在衍生類別中覆寫時,取得目前 Encoding 的字碼頁識別項。

(繼承來源 Encoding)
DecoderFallback

取得或設定目前 DecoderFallback 物件的 Encoding 物件。

(繼承來源 Encoding)
EncoderFallback

取得或設定目前 EncoderFallback 物件的 Encoding 物件。

(繼承來源 Encoding)
EncodingName

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

(繼承來源 Encoding)
HeaderName

在衍生類別中覆寫時,取得可以與郵件代理程式標頭標籤一起使用的目前編碼方式名稱。

(繼承來源 Encoding)
IsBrowserDisplay

在衍生類別中覆寫時,取得值,指出瀏覽器用戶端是否可以使用目前的編碼方式來顯示內容。

(繼承來源 Encoding)
IsBrowserSave

在衍生類別中覆寫時,取得值,指出瀏覽器用戶端是否可以使用目前的編碼方式來儲存內容。

(繼承來源 Encoding)
IsMailNewsDisplay

在衍生類別中覆寫時,取得值,指出郵件和新聞用戶端是否可以使用目前的編碼方式來顯示內容。

(繼承來源 Encoding)
IsMailNewsSave

在衍生類別中覆寫時,取得值,指出郵件和新聞用戶端是否可以使用目前的編碼方式來儲存內容。

(繼承來源 Encoding)
IsReadOnly

在衍生類別中覆寫時,取得值,指出目前的編碼方式是否為唯讀。

(繼承來源 Encoding)
IsSingleByte

在衍生類別中覆寫時,取得值,指出目前的編碼方式是否使用單一位元組字碼指標。

(繼承來源 Encoding)
Preamble

取得以 UTF-8 格式編碼的 Unicode 位元組順序標記 (若物件已設定為提供此項目)。

Preamble

在衍生類別中覆寫時,傳回範圍,其包含指定所用編碼方式的位元組序列。

(繼承來源 Encoding)
WebName

在衍生類別中覆寫時,若要取得目前的編碼方式,請取得向 Internet Assigned Numbers Authority (IANA) 註冊的名稱。

(繼承來源 Encoding)
WindowsCodePage

在衍生類別中覆寫時,請取得最能符合目前編碼方式的 Windows 作業系統字碼頁。

(繼承來源 Encoding)

方法

Clone()

在衍生類別中覆寫時,會建立目前 Encoding 物件的淺層複本。

(繼承來源 Encoding)
Equals(Object)

判斷指定的物件是否等於目前的 UTF8Encoding 物件。

GetByteCount(Char*, Int32)

計算將起始於指定字元指標的一組字元編碼所產生的位元組數目。

GetByteCount(Char*, Int32)

在衍生類別中覆寫時,計算從指定的字元指標開始,編碼一組字元所產生的位元組數目。

(繼承來源 Encoding)
GetByteCount(Char[])

在衍生類別中覆寫時,計算編碼指定字元陣列中所有字元所產生的位元組數目。

(繼承來源 Encoding)
GetByteCount(Char[], Int32, Int32)

計算將指定字元陣列中的一組字元編碼所產生的位元組數目。

GetByteCount(ReadOnlySpan<Char>)

計算將指定字元範圍編碼所產生的位元組數目。

GetByteCount(ReadOnlySpan<Char>)

在衍生類別中覆寫時,計算藉由編碼指定字元範圍中字元所產生的位元組數。

(繼承來源 Encoding)
GetByteCount(String)

計算將指定 String 中的字元編碼所產生的位元組數目。

GetByteCount(String, Int32, Int32)

在衍生類別中覆寫時,計算藉由從指定的字串編碼一組字元所產生的位元組數。

(繼承來源 Encoding)
GetBytes(Char*, Int32, Byte*, Int32)

將起始於指定字元指標的一組字元編碼成位元組序列;儲存該位元組序列時,係以指定的位元組指標為起始點。

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

在衍生類別中覆寫時,從指定字元指標開始將一組字元編碼成位元組序列 (會從指定的位元組指標開始存放這些位元組)。

(繼承來源 Encoding)
GetBytes(Char[])

在衍生類別中覆寫時,將指定字元陣列中的所有字元編碼成位元組序列。

(繼承來源 Encoding)
GetBytes(Char[], Int32, Int32)

在衍生類別中覆寫時,將指定字元陣列中的一組字元編碼成位元組序列。

(繼承來源 Encoding)
GetBytes(Char[], Int32, Int32, Byte[], Int32)

將指定字元陣列中的一組字元編碼成指定的位元組陣列。

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

將指定的字元範圍編碼為指定的位元組範圍。

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

在衍生類別中覆寫時,從指定的唯讀範圍將一組字元編碼到位元組範圍。

(繼承來源 Encoding)
GetBytes(String)

將指定 String 物件中的字元編碼成位元組序列。

GetBytes(String)

在衍生類別中覆寫時,將指定字串中的所有字元編碼成位元組序列。

(繼承來源 Encoding)
GetBytes(String, Int32, Int32)

在衍生類別中覆寫時,從指定字串中指定的 index 開始,將 count 指定的字元數編碼到位元組陣列。

(繼承來源 Encoding)
GetBytes(String, Int32, Int32, Byte[], Int32)

將指定 String 中的一組字元編碼成指定的位元組陣列。

GetCharCount(Byte*, Int32)

計算將起始於指定位元組指標的位元組序列解碼所產生的字元數。

GetCharCount(Byte*, Int32)

在衍生類別中覆寫時,計算從指定的位元組指標開始,解碼位元組序列所產生的字元數目。

(繼承來源 Encoding)
GetCharCount(Byte[])

在衍生類別中覆寫時,計算解碼指定位元組陣列中所有位元組所產生的字元數目。

(繼承來源 Encoding)
GetCharCount(Byte[], Int32, Int32)

計算將指定位元組陣列中的位元組序列解碼所產生的字元數。

GetCharCount(ReadOnlySpan<Byte>)

計算解碼指定位元組範圍所產生的字元數目。

GetCharCount(ReadOnlySpan<Byte>)

在衍生類別中覆寫時,計算藉由解碼所提供唯讀位元組範圍時產生的字元數。

(繼承來源 Encoding)
GetChars(Byte*, Int32, Char*, Int32)

將起始於指定位元組指標的位元組序列解碼成一組字元;儲存該組字元時,係以指定的字元指標為起始點。

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

在衍生類別中覆寫時,從指定位元組指標開始將位元組序列解碼成一組字元 (會從指定的字元指標開始存放這些字元)。

(繼承來源 Encoding)
GetChars(Byte[])

在衍生類別中覆寫時,將指定位元組陣列中的所有位元組解碼成一組字元。

(繼承來源 Encoding)
GetChars(Byte[], Int32, Int32)

在衍生類別中覆寫時,將指定位元組陣列中的位元組序列解碼成一組字元。

(繼承來源 Encoding)
GetChars(Byte[], Int32, Int32, Char[], Int32)

將指定位元組陣列中的位元組序列解碼成指定的字元陣列。

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

將指定的位元組範圍解碼為指定的字元範圍。

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

在衍生類別中覆寫時,將指定唯讀位元組範圍中的所有位元組解碼成字元範圍。

(繼承來源 Encoding)
GetDecoder()

取得可以將以 UTF-8 編碼的位元組序列轉換成 Unicode 字元序列的解碼器。

GetEncoder()

取得可以將 Unicode 字元序列轉換成以 UTF-8 編碼的位元組序列的編碼器。

GetHashCode()

傳回目前執行個體的雜湊碼。

GetMaxByteCount(Int32)

計算將指定數目的字元編碼所產生的最大位元組數目。

GetMaxCharCount(Int32)

計算將指定數目的位元組解碼所產生的最大字元數。

GetPreamble()

如果設定 UTF8Encoding 編碼物件提供編碼方式,則會傳回以 UTF-8 格式編碼的 Unicode 位元組順序標記。

GetString(Byte*, Int32)

在衍生類別中覆寫時,將指定位址開頭之指定數目的位元組解碼為字串。

(繼承來源 Encoding)
GetString(Byte[])

在衍生類別中覆寫時,將指定位元組陣列中的所有位元組解碼成字串。

(繼承來源 Encoding)
GetString(Byte[], Int32, Int32)

將位元組陣列中的某一段位元組範圍解碼成字串。

GetString(Byte[], Int32, Int32)

在衍生類別中覆寫時,將指定位元組陣列中的位元組序列解碼成字串。

(繼承來源 Encoding)
GetString(ReadOnlySpan<Byte>)

在衍生類別中覆寫時,將指定位元組範圍中的所有位元組解碼成字串。

(繼承來源 Encoding)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsAlwaysNormalized()

取得值,指出目前的編碼方式是否永遠都是使用預設的正規化表單進行正規化。

(繼承來源 Encoding)
IsAlwaysNormalized(NormalizationForm)

在衍生類別中覆寫時取得值,指出目前的編碼方式是否永遠都是使用指定的正規化表單進行正規化。

(繼承來源 Encoding)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TryGetBytes(ReadOnlySpan<Char>, Span<Byte>, Int32)

如果目的地夠大,則從指定的唯讀範圍將一組字元編碼為位元組範圍。

TryGetBytes(ReadOnlySpan<Char>, Span<Byte>, Int32)

如果目的地夠大,則從指定的唯讀範圍將一組字元編碼為位元組範圍。

(繼承來源 Encoding)
TryGetChars(ReadOnlySpan<Byte>, Span<Char>, Int32)

如果目的地夠大,則會將字元範圍從指定的唯讀範圍解碼為一組位元組。

TryGetChars(ReadOnlySpan<Byte>, Span<Char>, Int32)

如果目的地夠大,則會將字元範圍從指定的唯讀範圍解碼為一組位元組。

(繼承來源 Encoding)

擴充方法

GetBytes(Encoding, ReadOnlySequence<Char>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 編碼為 Byte 陣列。

GetBytes(Encoding, ReadOnlySequence<Char>, IBufferWriter<Byte>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 解碼為 byte,並將結果寫入到 writer

GetBytes(Encoding, ReadOnlySequence<Char>, Span<Byte>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 編碼為 byte,並將結果輸出到 bytes

GetBytes(Encoding, ReadOnlySpan<Char>, IBufferWriter<Byte>)

使用指定的 Encoding,將指定的 ReadOnlySpan<T> 編碼為 byte,並將結果寫入到 writer

GetChars(Encoding, ReadOnlySequence<Byte>, IBufferWriter<Char>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 解碼為 char,並將結果寫入到 writer

GetChars(Encoding, ReadOnlySequence<Byte>, Span<Char>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 解碼為 char,並將結果輸出至 chars

GetChars(Encoding, ReadOnlySpan<Byte>, IBufferWriter<Char>)

使用指定的 Encoding,將指定的 ReadOnlySpan<T> 解碼為 char,並將結果寫入到 writer

GetString(Encoding, ReadOnlySequence<Byte>)

使用指定的 Encoding,將指定的 ReadOnlySequence<T> 解碼為 String

適用於

另請參閱