UTF32Encoding 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 Unicode 字元的 UTF-32 編碼。
public ref class UTF32Encoding sealed : System::Text::Encoding
public sealed class UTF32Encoding : System.Text.Encoding
[System.Serializable]
public sealed class UTF32Encoding : System.Text.Encoding
type UTF32Encoding = class
inherit Encoding
[<System.Serializable>]
type UTF32Encoding = class
inherit Encoding
Public NotInheritable Class UTF32Encoding
Inherits Encoding
- 繼承
- 屬性
範例
以下範例展示了啟用錯誤偵測與未啟用錯誤偵測的 UTF32Encoding 物件行為。 它會建立一個位元組陣列,其最後四個位元組代表無效的代理對;高替代節點 U+D8FF 之後是 U+01FF,該指數位於低替代節點範圍之外(0xDC00 至 0xDFFF)。 在沒有錯誤偵測的情況下,UTF32 解碼器會使用替換備援,將無效的代理組合替換為替換字元(U+FFFD)。
using System;
using System.Text;
public class Example
{
public static void Main()
{
// Create a UTF32Encoding object with error detection enabled.
var encExc = new UTF32Encoding(! BitConverter.IsLittleEndian, true, true);
// Create a UTF32Encoding object with error detection disabled.
var encRepl = new UTF32Encoding(! BitConverter.IsLittleEndian, true, false);
// Create a byte arrays from a string, and add an invalid surrogate pair, as follows.
// Latin Small Letter Z (U+007A)
// Latin Small Letter A (U+0061)
// Combining Breve (U+0306)
// Latin Small Letter AE With Acute (U+01FD)
// Greek Small Letter Beta (U+03B2)
// a high-surrogate value (U+D8FF)
// an invalid low surrogate (U+01FF)
String s = "za\u0306\u01FD\u03B2";
// Encode the string using little-endian byte order.
int index = encExc.GetByteCount(s);
Byte[] bytes = new Byte[index + 4];
encExc.GetBytes(s, 0, s.Length, bytes, 0);
bytes[index] = 0xFF;
bytes[index + 1] = 0xD8;
bytes[index + 2] = 0xFF;
bytes[index + 3] = 0x01;
// Decode the byte array with error detection.
Console.WriteLine("Decoding with error detection:");
PrintDecodedString(bytes, encExc);
// Decode the byte array without error detection.
Console.WriteLine("Decoding without error detection:");
PrintDecodedString(bytes, encRepl);
}
// Decode the bytes and display the string.
public static void PrintDecodedString(Byte[] bytes, Encoding enc)
{
try {
Console.WriteLine(" Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length));
}
catch (DecoderFallbackException e) {
Console.WriteLine(e.ToString());
}
Console.WriteLine();
}
}
// The example displays the following output:
// Decoding with error detection:
// System.Text.DecoderFallbackException: Unable to translate bytes [FF][D8][FF][01] at index
// 20 from specified code page to Unicode.
// at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
// at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index
// )
// at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
// at System.Text.UTF32Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDeco
// der)
// at System.Text.UTF32Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
// at Example.PrintDecodedString(Byte[] bytes, Encoding enc)
//
// Decoding without error detection:
// Decoded string: zăǽβ�
Imports System.Text
Public Module Example
Public Sub Main()
' Create a UTF32Encoding object with error detection enabled.
Dim encExc As New UTF32Encoding(Not BitConverter.IsLittleEndian, True, True)
' Create a UTF32Encoding object with error detection disabled.
Dim encRepl As New UTF32Encoding(Not BitConverter.IsLittleEndian, True, False)
' Create a byte arrays from a string, and add an invalid surrogate pair, as follows.
' Latin Small Letter Z (U+007A)
' Latin Small Letter A (U+0061)
' Combining Breve (U+0306)
' Latin Small Letter AE With Acute (U+01FD)
' Greek Small Letter Beta (U+03B2)
' a high-surrogate value (U+D8FF)
' an invalid low surrogate (U+01FF)
Dim s As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2)
' Encode the string using little-endian byte order.
Dim index As Integer = encExc.GetBytecount(s)
Dim bytes(index + 3) As Byte
encExc.GetBytes(s, 0, s.Length, bytes, 0)
bytes(index) = &hFF
bytes(index + 1) = &hD8
bytes(index + 2) = &hFF
bytes(index + 3) = &h01
' Decode the byte array with error detection.
Console.WriteLine("Decoding with error detection:")
PrintDecodedString(bytes, encExc)
' Decode the byte array without error detection.
Console.WriteLine("Decoding without error detection:")
PrintDecodedString(bytes, encRepl)
End Sub
' Decode the bytes and display the string.
Public Sub PrintDecodedString(bytes() As Byte, enc As Encoding)
Try
Console.WriteLine(" Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length))
Catch e As DecoderFallbackException
Console.WriteLine(e.ToString())
End Try
Console.WriteLine()
End Sub
End Module
' The example displays the following output:
' Decoding with error detection:
' System.Text.DecoderFallbackException: Unable to translate bytes [FF][D8][FF][01] at index
' 20 from specified code page to Unicode.
' at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
' at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index
' )
' at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
' at System.Text.UTF32Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDeco
' der)
' at System.Text.UTF32Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
' at Example.PrintDecodedString(Byte[] bytes, Encoding enc)
'
' Decoding without error detection:
' Decoded string: zăǽβ�
以下範例透過使用物件 UTF32Encoding 將一串 Unicode 字元編碼成位元組陣列。 接著將位元組陣列解碼成字串,以證明資料不會遺失。
using System;
using System.Text;
public class Example
{
public static void Main()
{
// The encoding.
var enc = new UTF32Encoding();
// Create a string.
String s = "This string contains two characters " +
"with codes outside the ASCII code range: " +
"Pi (\u03A0) and Sigma (\u03A3).";
Console.WriteLine("Original string:");
Console.WriteLine(" {0}", s);
// Encode the string.
Byte[] encodedBytes = enc.GetBytes(s);
Console.WriteLine();
Console.WriteLine("Encoded bytes:");
for (int ctr = 0; ctr < encodedBytes.Length; ctr++) {
Console.Write("[{0:X2}]{1}", encodedBytes[ctr],
(ctr + 1) % 4 == 0 ? " " : "" );
if ((ctr + 1) % 16 == 0) Console.WriteLine();
}
Console.WriteLine();
// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = enc.GetString(encodedBytes);
Console.WriteLine();
Console.WriteLine("Decoded string:");
Console.WriteLine(" {0}", decodedString);
}
}
// The example displays the following output:
// Original string:
// This string contains two characters with codes outside the ASCII code range:
// Pi (π) and Sigma (Σ).
//
// Encoded bytes:
// [54][00][00][00] [68][00][00][00] [69][00][00][00] [73][00][00][00]
// [20][00][00][00] [73][00][00][00] [74][00][00][00] [72][00][00][00]
// [69][00][00][00] [6E][00][00][00] [67][00][00][00] [20][00][00][00]
// [63][00][00][00] [6F][00][00][00] [6E][00][00][00] [74][00][00][00]
// [61][00][00][00] [69][00][00][00] [6E][00][00][00] [73][00][00][00]
// [20][00][00][00] [74][00][00][00] [77][00][00][00] [6F][00][00][00]
// [20][00][00][00] [63][00][00][00] [68][00][00][00] [61][00][00][00]
// [72][00][00][00] [61][00][00][00] [63][00][00][00] [74][00][00][00]
// [65][00][00][00] [72][00][00][00] [73][00][00][00] [20][00][00][00]
// [77][00][00][00] [69][00][00][00] [74][00][00][00] [68][00][00][00]
// [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
// [65][00][00][00] [73][00][00][00] [20][00][00][00] [6F][00][00][00]
// [75][00][00][00] [74][00][00][00] [73][00][00][00] [69][00][00][00]
// [64][00][00][00] [65][00][00][00] [20][00][00][00] [74][00][00][00]
// [68][00][00][00] [65][00][00][00] [20][00][00][00] [41][00][00][00]
// [53][00][00][00] [43][00][00][00] [49][00][00][00] [49][00][00][00]
// [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
// [65][00][00][00] [20][00][00][00] [72][00][00][00] [61][00][00][00]
// [6E][00][00][00] [67][00][00][00] [65][00][00][00] [3A][00][00][00]
// [20][00][00][00] [50][00][00][00] [69][00][00][00] [20][00][00][00]
// [28][00][00][00] [A0][03][00][00] [29][00][00][00] [20][00][00][00]
// [61][00][00][00] [6E][00][00][00] [64][00][00][00] [20][00][00][00]
// [53][00][00][00] [69][00][00][00] [67][00][00][00] [6D][00][00][00]
// [61][00][00][00] [20][00][00][00] [28][00][00][00] [A3][03][00][00]
// [29][00][00][00] [2E][00][00][00]
//
// Decoded string:
// This string contains two characters with codes outside the ASCII code range:
// Pi (π) and Sigma (Σ).
Imports System.Text
Class Example
Public Shared Sub Main()
' The encoding.
Dim enc As New UTF32Encoding()
' Create a string.
Dim s As String =
"This string contains two characters " &
"with codes outside the ASCII code range: " &
"Pi (" & ChrW(&h03A0) & ") and Sigma (" & ChrW(&h03A3) & ")."
Console.WriteLine("Original string:")
Console.WriteLine(" {0}", s)
' Encode the string.
Dim encodedBytes As Byte() = enc.GetBytes(s)
Console.WriteLine()
Console.WriteLine("Encoded bytes:")
For ctr As Integer = 0 To encodedBytes.Length - 1
Console.Write("[{0:X2}]{1}", encodedBytes(ctr),
If((ctr + 1) Mod 4 = 0, " ", "" ))
If (ctr + 1) Mod 16 = 0 Then Console.WriteLine()
Next
Console.WriteLine()
' Decode bytes back to string.
' Notice Pi and Sigma characters are still present.
Dim decodedString As String = enc.GetString(encodedBytes)
Console.WriteLine()
Console.WriteLine("Decoded string:")
Console.WriteLine(" {0}", decodedString)
End Sub
End Class
' The example displays the following output:
' Original string:
' This string contains two characters with codes outside the ASCII code range:
' Pi (π) and Sigma (Σ).
'
' Encoded bytes:
' [54][00][00][00] [68][00][00][00] [69][00][00][00] [73][00][00][00]
' [20][00][00][00] [73][00][00][00] [74][00][00][00] [72][00][00][00]
' [69][00][00][00] [6E][00][00][00] [67][00][00][00] [20][00][00][00]
' [63][00][00][00] [6F][00][00][00] [6E][00][00][00] [74][00][00][00]
' [61][00][00][00] [69][00][00][00] [6E][00][00][00] [73][00][00][00]
' [20][00][00][00] [74][00][00][00] [77][00][00][00] [6F][00][00][00]
' [20][00][00][00] [63][00][00][00] [68][00][00][00] [61][00][00][00]
' [72][00][00][00] [61][00][00][00] [63][00][00][00] [74][00][00][00]
' [65][00][00][00] [72][00][00][00] [73][00][00][00] [20][00][00][00]
' [77][00][00][00] [69][00][00][00] [74][00][00][00] [68][00][00][00]
' [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
' [65][00][00][00] [73][00][00][00] [20][00][00][00] [6F][00][00][00]
' [75][00][00][00] [74][00][00][00] [73][00][00][00] [69][00][00][00]
' [64][00][00][00] [65][00][00][00] [20][00][00][00] [74][00][00][00]
' [68][00][00][00] [65][00][00][00] [20][00][00][00] [41][00][00][00]
' [53][00][00][00] [43][00][00][00] [49][00][00][00] [49][00][00][00]
' [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
' [65][00][00][00] [20][00][00][00] [72][00][00][00] [61][00][00][00]
' [6E][00][00][00] [67][00][00][00] [65][00][00][00] [3A][00][00][00]
' [20][00][00][00] [50][00][00][00] [69][00][00][00] [20][00][00][00]
' [28][00][00][00] [A0][03][00][00] [29][00][00][00] [20][00][00][00]
' [61][00][00][00] [6E][00][00][00] [64][00][00][00] [20][00][00][00]
' [53][00][00][00] [69][00][00][00] [67][00][00][00] [6D][00][00][00]
' [61][00][00][00] [20][00][00][00] [28][00][00][00] [A3][03][00][00]
' [29][00][00][00] [2E][00][00][00]
'
' Decoded string:
' This string contains two characters with codes outside the ASCII code 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-32 encoding that supports a BOM.
var enc = new UTF32Encoding();
// A Unicode string with two characters outside an 8-bit code range.
String s = "This Unicode string has 2 characters " +
"outside the ASCII range: \n" +
"Pi (\u03A0), and Sigma (\u03A3).";
Console.WriteLine("Original string:");
Console.WriteLine(s);
Console.WriteLine();
// Encode the string.
Byte[] encodedBytes = enc.GetBytes(s);
Console.WriteLine("The encoded string has {0} bytes.\n",
encodedBytes.Length);
// Write the bytes to a file with a BOM.
var fs = new FileStream(@".\UTF32Encoding.txt", FileMode.Create);
Byte[] bom = enc.GetPreamble();
fs.Write(bom, 0, bom.Length);
fs.Write(encodedBytes, 0, encodedBytes.Length);
Console.WriteLine("Wrote {0} bytes to the file.\n", fs.Length);
fs.Close();
// Open the file using StreamReader.
var sr = new StreamReader(@".\UTF32Encoding.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(@".\Utf32Encoding.txt", FileMode.Open);
Byte[] bytes = new Byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
String decodedString = enc.GetString(bytes);
Console.WriteLine("Decoded bytes from binary file:");
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 340 bytes.
//
// Wrote 344 bytes to the file.
//
// String read using StreamReader:
// This Unicode string has 2 characters outside the ASCII range:
// Pi (π), and Sigma (Σ).
//
// Decoded bytes from binary file:
// 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-32 encoding that supports a BOM.
Dim enc As New UTF32Encoding()
' A Unicode string with two characters outside an 8-bit code range.
Dim s 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(s)
Console.WriteLine()
' Encode the string.
Dim encodedBytes As Byte() = enc.GetBytes(s)
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(".\UTF32Encoding.txt", FileMode.Create)
Dim bom() As Byte = enc.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(".\UTF32Encoding.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(".\Utf32Encoding.txt", FileMode.Open)
Dim bytes(fs.Length - 1) As Byte
fs.Read(bytes, 0, fs.Length)
fs.Close()
Dim decodedString As String = enc.GetString(bytes)
Console.WriteLine("Decoded bytes from binary file:")
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 344 bytes.
'
' Wrote 348 bytes to the file.
'
' String read using StreamReader:
' This Unicode string has 2 characters outside the ASCII range:
' Pi (π), and Sigma (Σ).
'
' Decoded bytes from binary file:
' This Unicode string has 2 characters outside the ASCII range:
' Pi (π), and Sigma (Σ).
備註
編碼是將一組 Unicode 字元轉換成位元組序列的程式。 解碼是將一連串編碼好的位元組轉換成一組 Unicode 字元的過程。
Unicode 標準會為每個支援的文字中的每個字元指派一個代碼點(數字)。 Unicode 轉換格式(UTF)是一種編碼該碼點的方法。 Unicode 標準使用以下 UTF:
UTF-8,將每個碼點以一到四個位元組的序列表示。
UTF-16,將每個碼點以一到兩個16位元整數序列表示。
UTF-32,將每個碼點表示為 32 位元整數。
欲了解更多關於 所支援 System.Text的 UTF 及其他編碼的資訊,請參見 .NET 中的字元編碼。
該 UTF32Encoding 類別代表一種 UTF-32 編碼。 編碼器可以使用大端序位元組序(最有效位元組先行)或小端序位元組序(最低有效位元組先行)。 例如,拉丁字母 A(代碼點 U+0041)的序列如下(十六進位):
大端序位元組序:00 00 00 41
小端序位元組序:41 00 00 00
使用原生位元節順序來儲存 Unicode 字元通常更有效率。 例如,最好在小端平臺上使用小位元組位元組順序,例如 Intel 計算機。 UTF32Encoding 對應 Windows 代碼頁 12000(小端位元組序)與 12001(大端序位元組序)。 你可以透過呼叫 BitConverter.IsLittleEndian 該方法來判斷特定架構的「端序性」。
物件可 UTF32Encoding 選擇性地提供位元組順序標記(BOM),這是一個可加在編碼過程產生的位元組序列前綴的位元組陣列。 如果前導碼包含位元組順序標記(BOM),它有助於解碼器決定位元組陣列的位元組順序及轉換格式(UTF)。
如果實 UTF32Encoding 例設定提供物料清單(BOM),你可以透過呼叫該 GetPreamble 方法來取得;否則,方法會回傳一個空陣列。 請注意,即使 UTF32Encoding 物件已設定為 BOM 支援,也必須在編碼的位元組流開頭適當地包含 BOM;類別的 UTF32Encoding 編碼方法不會自動做到這點。
Caution
為了啟用錯誤偵測並提升類別實例的安全,你應該透過呼叫UTF32Encoding(Boolean, Boolean, Boolean)建構子並將其參數true設throwOnInvalidBytes為 來實例化物件UTF32Encoding。 在錯誤偵測中,偵測到無效字元序列或位元組的方法會拋 ArgumentException 出例外。 若沒有錯誤偵測,則不會拋出例外,且無效序列通常會被忽略。
你可以用多種方式實例化一個 UTF32Encoding 物件,取決於你是否希望它提供位元組順序標記(BOM)、你想要大端還是小端編碼,以及你是否想啟用錯誤偵測。 下表列出了回傳UnicodeEncoding物件的UTF32Encoding建構子與Encoding屬性。
| 會員 | 位元組序 | BOM | 錯誤偵測 |
|---|---|---|---|
| Encoding.UTF32 | 小端序 | 是的 | 不行(替代備用) |
| UTF32Encoding.UTF32Encoding() | 小端序 | 是的 | 不行(替代備用) |
| UTF32Encoding.UTF32Encoding(Boolean, Boolean) | Configurable | Configurable | 不行(替代備用) |
| UTF32Encoding.UTF32Encoding(Boolean, Boolean, Boolean) | Configurable | Configurable | Configurable |
該 GetByteCount 方法決定編碼一組 Unicode 字元的位元組數,並 GetBytes 執行實際編碼。
同樣地,方法 GetCharCount 決定解碼一串位元組的字元數,而 和 GetCharsGetString 方法則執行實際解碼。
對於能在編碼或解碼跨多個區塊的資料(例如以 100,000 字元區段編碼的 100 萬字元字串)時儲存狀態資訊的編碼器或解碼器,分別使用 GetEncoder 和 GetDecoder 屬性。
建構函式
| 名稱 | Description |
|---|---|
| UTF32Encoding() |
初始化 UTF32Encoding 類別的新執行個體。 |
| UTF32Encoding(Boolean, Boolean, Boolean) |
初始化 UTF32Encoding 類別的新執行個體。 參數會指定是否使用大端序位元組序、是否提供 Unicode 位元組序標記,以及當偵測到無效編碼時是否拋出例外。 |
| UTF32Encoding(Boolean, Boolean) |
初始化 UTF32Encoding 類別的新執行個體。 參數會指定是否使用大端序位元組序,以及方法是否 GetPreamble() 回傳 Unicode 位元組序標記。 |
屬性
| 名稱 | Description |
|---|---|
| BodyName |
當在衍生類別中覆寫時,會獲得一個可用於郵件代理體標籤的當前編碼名稱。 (繼承來源 Encoding) |
| CodePage |
當在衍生類別中被覆寫時,會獲得目前 Encoding的代碼頁識別碼。 (繼承來源 Encoding) |
| DecoderFallback |
取得或設定 DecoderFallback 當前 Encoding 物件的物件。 (繼承來源 Encoding) |
| EncoderFallback |
取得或設定 EncoderFallback 當前 Encoding 物件的物件。 (繼承來源 Encoding) |
| EncodingName |
當在衍生類別中覆寫時,會得到目前編碼的人類可讀描述。 (繼承來源 Encoding) |
| HeaderName |
當 在衍生類別中被覆寫時,會獲得一個可用於郵件代理標頭標籤的當前編碼名稱。 (繼承來源 Encoding) |
| IsBrowserDisplay |
當 在衍生類別中覆寫時,會獲得一個值,表示瀏覽器客戶端是否可以使用目前的編碼來顯示內容。 (繼承來源 Encoding) |
| IsBrowserSave |
當在衍生類別中覆寫時,會獲得一個值,表示瀏覽器客戶端是否能使用目前的編碼來儲存內容。 (繼承來源 Encoding) |
| IsMailNewsDisplay |
當在派生類別中覆寫時,會獲得一個值,表示目前的編碼是否可用於郵件和新聞用戶端顯示內容。 (繼承來源 Encoding) |
| IsMailNewsSave |
當在衍生類別中覆寫時,會獲得一個值,表示目前的編碼是否能被郵件和新聞客戶端用來儲存內容。 (繼承來源 Encoding) |
| IsReadOnly |
當在衍生類別中覆寫時,會獲得一個值,表示目前編碼是否為唯讀。 (繼承來源 Encoding) |
| IsSingleByte |
當在派生類別中覆寫時,會得到一個值,表示目前編碼是否使用單位元組的碼點。 (繼承來源 Encoding) |
| Preamble |
如果這個物件設定為提供一個,則取得以UTF-32格式編碼的Unicode位元組順序標記。 |
| Preamble |
當在衍生類別中覆寫時,會回傳一個包含指定所用編碼序列的位元組的區間。 (繼承來源 Encoding) |
| WebName |
當在衍生類別中被覆寫時,會獲得目前編碼的名稱,註冊於網際網路號碼分配管理局(IANA)。 (繼承來源 Encoding) |
| WindowsCodePage |
當在衍生類別中覆寫時,會得到與目前編碼最接近的 Windows 作業系統代碼頁。 (繼承來源 Encoding) |
方法
| 名稱 | Description |
|---|---|
| Clone() |
當在衍生類別中覆寫時,會產生目前 Encoding 物件的淺層副本。 (繼承來源 Encoding) |
| Equals(Object) |
判斷指定的 Object 是否等於當前 UTF32Encoding 物件。 |
| GetByteCount(Char[], Int32, Int32) |
計算從指定字元陣列編碼一組字元所產生的位元組數。 |
| GetByteCount(Char[]) |
當在派生類別中覆寫時,會計算將指定字元陣列中所有字元編碼所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(Char*, Int32) |
計算從指定字元指標開始編碼一組字元所產生的位元組數。 |
| GetByteCount(ReadOnlySpan<Char>) |
當在派生類別中覆寫時,會計算在指定字元區間內編碼字元所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(String, Int32, Int32) |
當在派生類別中覆寫時,會計算從指定字串編碼一組字元所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(String) |
計算透過編碼指定 String字元所產生的位元組數。 |
| GetBytes(Char[], Int32, Int32, Byte[], Int32) |
將指定字元陣列中的一組字元編碼到指定的位元組陣列中。 |
| GetBytes(Char[], Int32, Int32) |
當在派生類別中覆寫時,會將指定字元陣列中的一組字元編碼成一串位元組。 (繼承來源 Encoding) |
| GetBytes(Char[]) |
當在派生類別中覆寫時,會將指定字元陣列中的所有字元編碼成一串位元組。 (繼承來源 Encoding) |
| GetBytes(Char*, Int32, Byte*, Int32) |
將一組從指定字元指標開始的字元編碼成一串位元組,並從指定位元組指標開始儲存。 |
| GetBytes(ReadOnlySpan<Char>, Span<Byte>) |
當在派生類別中覆寫時,會將指定唯讀區間的一組字元編碼到位元組區間。 (繼承來源 Encoding) |
| GetBytes(String, Int32, Int32, Byte[], Int32) |
將指定的 String 一組字元編碼到指定的位元組陣列中。 |
| GetBytes(String, Int32, Int32) |
當在派生類別中覆寫時,會將指定字串中指定的 |
| GetBytes(String) |
當在派生類別中覆寫時,會將指定字串中的所有字元編碼成一串位元組。 (繼承來源 Encoding) |
| GetCharCount(Byte[], Int32, Int32) |
計算從指定位元組陣列解碼一串位元組所產生的字元數。 |
| GetCharCount(Byte[]) |
當在派生類別中覆寫時,會計算解碼指定位元組陣列中所有位元組所產生的字元數。 (繼承來源 Encoding) |
| GetCharCount(Byte*, Int32) |
透過解碼從指定位元組指標開始的一串位元組來計算字元數。 |
| GetCharCount(ReadOnlySpan<Byte>) |
當在衍生類別中覆寫時,會計算出解碼所提供的唯讀位元組區間所產生的字元數。 (繼承來源 Encoding) |
| GetChars(Byte[], Int32, Int32, Char[], Int32) |
將指定位元組陣列的一串位元組解碼到指定的字元陣列。 |
| GetChars(Byte[], Int32, Int32) |
當在派生類別中覆寫時,會將指定位元組陣列中的一串位元組解碼成一組字元。 (繼承來源 Encoding) |
| GetChars(Byte[]) |
當在派生類別中覆寫時,會將指定位元組陣列中的所有位元組解碼成一組字元。 (繼承來源 Encoding) |
| GetChars(Byte*, Int32, Char*, Int32) |
將從指定位元組指標開始的一串位元組解碼成一組字元,這些字元從指定字元指標開始儲存。 |
| GetChars(ReadOnlySpan<Byte>, Span<Char>) |
當在派生類別中覆寫時,會將指定唯讀位元組區間中的所有位元組解碼為字元區間。 (繼承來源 Encoding) |
| GetDecoder() |
取得一個解碼器,能將 UTF-32 編碼的位元組序列轉換成 Unicode 字元序列。 |
| GetEncoder() |
取得一個編碼器,能將一串 Unicode 字元轉換成 UTF-32 編碼的位元組序列。 |
| GetHashCode() |
傳回目前實例的哈希碼。 |
| GetMaxByteCount(Int32) |
計算編碼指定字元數所產生的最大位元組數。 |
| GetMaxCharCount(Int32) |
計算解碼指定位元組數後產生的最大字元數。 |
| GetPreamble() |
若 UTF32Encoding 物件設定提供 UTF-32 格式,則回傳一個以 UTF-32 格式編碼的 Unicode 位元組順序標記。 |
| GetString(Byte[], Int32, Int32) |
將位元組陣列中的位元組範圍解碼成字串。 |
| GetString(Byte[]) |
當在衍生類別中覆寫時,會將指定位元組陣列中的所有位元組解碼成一個字串。 (繼承來源 Encoding) |
| GetString(Byte*, 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) |
如果目的地夠大,則會將指定唯讀區段中的一組字元編碼成位元組區間。 (繼承來源 Encoding) |
| TryGetChars(ReadOnlySpan<Byte>, Span<Char>, Int32) |
如果目的地夠大,則會將指定唯讀區段中的一組位元組解碼成字元區間。 (繼承來源 Encoding) |
擴充方法
| 名稱 | Description |
|---|---|
| GetBytes(Encoding, ReadOnlySequence<Char>, IBufferWriter<Byte>) |
利用指定ReadOnlySequence<T>條件解碼 |
| GetBytes(Encoding, ReadOnlySequence<Char>, Span<Byte>) |
將指定 ReadOnlySequence<T> 內容編碼為 |
| GetBytes(Encoding, ReadOnlySequence<Char>) |
將指定 ReadOnlySequence<T> 編碼成 Byte 一個陣列,使用指定的 Encoding。 |
| GetBytes(Encoding, ReadOnlySpan<Char>, IBufferWriter<Byte>) |
將指定 ReadOnlySpan<T> 內容編碼為 |
| GetChars(Encoding, ReadOnlySequence<Byte>, IBufferWriter<Char>) |
利用指定ReadOnlySequence<T>條件解碼 |
| GetChars(Encoding, ReadOnlySequence<Byte>, Span<Char>) |
利用指定ReadOnlySequence<T>條件將指定 |
| GetChars(Encoding, ReadOnlySpan<Byte>, IBufferWriter<Char>) |
利用指定ReadOnlySpan<T>條件解碼 |
| GetString(Encoding, ReadOnlySequence<Byte>) |
利用指定的 ReadOnlySequence<T>將 解碼String為 。Encoding |