UTF7Encoding 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 Unicode 字元的 UTF-7 編碼。
public ref class UTF7Encoding : System::Text::Encoding
public class UTF7Encoding : System.Text.Encoding
[System.Serializable]
public class UTF7Encoding : System.Text.Encoding
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class UTF7Encoding : System.Text.Encoding
type UTF7Encoding = class
inherit Encoding
[<System.Serializable>]
type UTF7Encoding = class
inherit Encoding
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type UTF7Encoding = class
inherit Encoding
Public Class UTF7Encoding
Inherits Encoding
- 繼承
- 屬性
範例
以下程式碼範例示範如何使用 來 UTF7Encoding 編碼一串 Unicode 字元並將其儲存在位元組陣列中。 注意當位元組陣列解碼回字串時,資料不會遺失。
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
// Create a UTF-7 encoding.
UTF7Encoding utf7 = new UTF7Encoding();
// A Unicode string with two characters outside a 7-bit code range.
String unicodeString =
"This Unicode string contains two characters " +
"with codes outside a 7-bit code range, " +
"Pi (\u03a0) and Sigma (\u03a3).";
Console.WriteLine("Original string:");
Console.WriteLine(unicodeString);
// Encode the string.
Byte[] encodedBytes = utf7.GetBytes(unicodeString);
Console.WriteLine();
Console.WriteLine("Encoded bytes:");
foreach (Byte b in encodedBytes) {
Console.Write("[{0}]", b);
}
Console.WriteLine();
// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = utf7.GetString(encodedBytes);
Console.WriteLine();
Console.WriteLine("Decoded bytes:");
Console.WriteLine(decodedString);
}
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class UTF7EncodingExample
Public Shared Sub Main()
' Create a UTF-7 encoding.
Dim utf7 As New UTF7Encoding()
' A Unicode string with two characters outside a 7-bit code range.
Dim unicodeString As String = _
"This Unicode string contains two characters " & _
"with codes outside a 7-bit code range, " & _
"Pi (" & ChrW(928) & ") and Sigma (" & ChrW(931) & ")."
Console.WriteLine("Original string:")
Console.WriteLine(unicodeString)
' Encode the string.
Dim encodedBytes As Byte() = utf7.GetBytes(unicodeString)
Console.WriteLine()
Console.WriteLine("Encoded bytes:")
Dim b As Byte
For Each b In encodedBytes
Console.Write("[{0}]", b)
Next b
Console.WriteLine()
' Decode bytes back to string.
' Notice Pi and Sigma characters are still present.
Dim decodedString As String = utf7.GetString(encodedBytes)
Console.WriteLine()
Console.WriteLine("Decoded bytes:")
Console.WriteLine(decodedString)
End Sub
End Class
備註
編碼是將一組 Unicode 字元轉換成位元組序列的程式。 解碼是將一連串編碼好的位元組轉換成一組 Unicode 字元的過程。
UTF-7 編碼將 Unicode 字元表示為 7 位元 ASCII 字元序列。 此編碼支援特定協定,通常是電子郵件或新聞群組協定。 由於 UTF-7 並不特別安全或穩健,且大多數現代系統都支援 8 位元編碼,因此通常應該優先使用 UTF-8 而非 UTF-7。
Note
UTF7Encoding 無法提供錯誤偵測。 出於安全考量,應用程式應使用 UTF8Encoding、 UnicodeEncoding或 , UTF32Encoding 並啟用錯誤偵測。
欲了解更多關於 支援的 UTF 及其他 System.Text編碼的資訊,請參閱 .NET Framework 中的字元編碼。
該 GetByteCount 方法決定編碼一組 Unicode 字元的位元組數,並 GetBytes 執行實際編碼。
同樣地,方法 GetCharCount 決定解碼一串位元組的字元數,而 和 GetCharsGetString 方法則執行實際解碼。
UTF7Encoding 對應於Windows代碼頁 65000。
Note
若 UTF-7 編碼物件使用不同的 .NET Framework 版本序列化與反序列化,其狀態不會被保留。
建構函式
| 名稱 | Description |
|---|---|
| UTF7Encoding() |
初始化 UTF7Encoding 類別的新執行個體。 |
| UTF7Encoding(Boolean) |
初始化 UTF7Encoding 類別的新執行個體。 參數指定是否允許可選字元。 |
屬性
| 名稱 | 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 |
當在衍生類別中覆寫時,會回傳一個包含指定所用編碼序列的位元組的區間。 (繼承來源 Encoding) |
| WebName |
當在衍生類別中被覆寫時,會獲得目前編碼的名稱,註冊於網際網路號碼分配管理局(IANA)。 (繼承來源 Encoding) |
| WindowsCodePage |
當在衍生類別中覆寫時,會得到與目前編碼最接近的 Windows 作業系統代碼頁。 (繼承來源 Encoding) |
方法
| 名稱 | Description |
|---|---|
| Clone() |
當在衍生類別中覆寫時,會產生目前 Encoding 物件的淺層副本。 (繼承來源 Encoding) |
| Equals(Object) |
會得到一個值,表示指定的物件是否等於當前 UTF7Encoding 物件。 |
| Equals(Object) |
判斷指定的 Object 是否等於當前實例。 (繼承來源 Encoding) |
| GetByteCount(Char[], Int32, Int32) |
計算從指定字元陣列編碼一組字元所產生的位元組數。 |
| GetByteCount(Char[]) |
當在派生類別中覆寫時,會計算將指定字元陣列中所有字元編碼所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(Char*, Int32) |
計算從指定字元指標開始編碼一組字元所產生的位元組數。 |
| GetByteCount(ReadOnlySpan<Char>) |
當在派生類別中覆寫時,會計算在指定字元區間內編碼字元所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(String, Int32, Int32) |
當在派生類別中覆寫時,會計算從指定字串編碼一組字元所產生的位元組數。 (繼承來源 Encoding) |
| GetByteCount(String) |
計算透過編碼指定 String 物件中字元所產生的位元組數。 |
| GetByteCount(String) |
當在衍生類別中覆寫時,會計算出編碼指定字串字元所產生的位元組數。 (繼承來源 Encoding) |
| 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, Byte[], Int32) |
當在派生類別中覆寫時,會將指定字串中的一組字元編碼到指定的位元組陣列中。 (繼承來源 Encoding) |
| 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-7 編碼的位元組序列轉換為 Unicode 字元序列。 |
| GetEncoder() |
取得一個編碼器,能將一串 Unicode 字元轉換成 UTF-7 編碼的位元組序列。 |
| GetHashCode() |
回傳當前 UTF7Encoding 物件的雜湊碼。 |
| GetHashCode() |
傳回目前實例的哈希碼。 (繼承來源 Encoding) |
| GetMaxByteCount(Int32) |
計算編碼指定字元數所產生的最大位元組數。 |
| GetMaxCharCount(Int32) |
計算解碼指定位元組數後產生的最大字元數。 |
| GetPreamble() |
當在派生類別中覆寫時,會回傳一串位元組,指定所使用的編碼方式。 (繼承來源 Encoding) |
| GetString(Byte[], Int32, Int32) |
將位元組陣列中的位元組範圍解碼成字串。 |
| GetString(Byte[], Int32, Int32) |
當在派生類別中覆寫時,會將指定位元組陣列中的一串位元組解碼成字串。 (繼承來源 Encoding) |
| GetString(Byte[]) |
當在衍生類別中覆寫時,會將指定位元組陣列中的所有位元組解碼成一個字串。 (繼承來源 Encoding) |
| GetString(Byte*, Int32) |
當在派生類別中覆寫時,會將從指定位址開始的指定位元組解碼成字串。 (繼承來源 Encoding) |
| GetString(ReadOnlySpan<Byte>) |
當在派生類別中覆寫時,會將指定位元組區間中的所有位元組解碼成一個字串。 (繼承來源 Encoding) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsAlwaysNormalized() |
會得到一個值,表示目前編碼是否總是正規化,使用預設的正規化形式。 (繼承來源 Encoding) |
| IsAlwaysNormalized(NormalizationForm) |
當在派生類別中覆寫時,會得到一個值,表示目前編碼是否總是被正規化,並使用指定的正規化形式。 (繼承來源 Encoding) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |