System.Text Namespace

System.Text 命名空間包含代表 ASCII 和 Unicode 字元編碼的類別;用來將字元區塊與位元組區塊來回轉換的抽象基底類別;以及管理和格式化 String 物件,而不需要建立 String 的中繼執行個體的協助程式類別。 The System.Text namespace contains classes that represent ASCII and Unicode character encodings; abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats String objects without creating intermediate instances of String.

類別

ASCIIEncoding

代表 Unicode 字元的 ASCII 字元編碼方式。Represents an ASCII character encoding of Unicode characters.

CodePagesEncodingProvider

將字碼頁存取權提供給編碼提供者,否則只能在桌面 .NET Framework 中使用。Provides access to an encoding provider for code pages that otherwise are available only in the desktop .NET Framework.

Decoder

將編碼的位元組序列轉換成一組字元。Converts a sequence of encoded bytes into a set of characters.

DecoderExceptionFallback

針對無法轉換為輸入字元的編碼輸入位元組序列,提供失敗處理機制 (稱為後援)。Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an input character. 後援會擲回例外狀況,而不會將輸入位元組序列解碼。The fallback throws an exception instead of decoding the input byte sequence. 這個類別無法被繼承。This class cannot be inherited.

DecoderExceptionFallbackBuffer

當編碼的輸入位元組序列無法轉換成已解碼的輸出字元時,會擲回 DecoderFallbackExceptionThrows DecoderFallbackException when an encoded input byte sequence cannot be converted to a decoded output character. 這個類別無法被繼承。This class cannot be inherited.

DecoderFallback

針對無法轉換為輸出字元的編碼輸入位元組序列,提供失敗處理機制 (稱為後援)。Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an output character.

DecoderFallbackBuffer

提供緩衝區,允許後援處理常式在無法解碼輸入位元組序列時,將替代字串傳回至解碼器。Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it cannot decode an input byte sequence.

DecoderFallbackException

當解碼器後援作業失敗時,所擲回的例外狀況。The exception that is thrown when a decoder fallback operation fails. 這個類別無法被繼承。This class cannot be inherited.

DecoderReplacementFallback

針對無法轉換為輸出字元的編碼輸入位元組序列,提供失敗處理機制 (稱為後援)。Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an output character. 此後援會發出使用者指定的取代字串,而非已解碼的輸入位元組序列。The fallback emits a user-specified replacement string instead of a decoded input byte sequence. 這個類別無法被繼承。This class cannot be inherited.

DecoderReplacementFallbackBuffer

表示在無法解碼原始輸入位元組序列時,所發出的替代輸出字串。Represents a substitute output string that is emitted when the original input byte sequence cannot be decoded. 這個類別無法被繼承。This class cannot be inherited.

Encoder

將一組字元轉換成位元組序列。Converts a set of characters into a sequence of bytes.

EncoderExceptionFallback

針對無法轉換為輸出位元組序列的輸入字元,提供失敗處理機制 (稱為後援)。Provides a failure-handling mechanism, called a fallback, for an input character that cannot be converted to an output byte sequence. 如果輸入字元無法轉換成輸出位元組序列,後援會擲回例外狀況。The fallback throws an exception if an input character cannot be converted to an output byte sequence. 這個類別無法被繼承。This class cannot be inherited.

EncoderExceptionFallbackBuffer

當輸入字元無法轉換成編碼的輸出位元組序列時,會擲回 EncoderFallbackExceptionThrows EncoderFallbackException when an input character cannot be converted to an encoded output byte sequence. 這個類別無法被繼承。This class cannot be inherited.

EncoderFallback

針對無法轉換為編碼輸出位元組序列的輸入字元,提供失敗處理機制 (稱為後援)。Provides a failure-handling mechanism, called a fallback, for an input character that cannot be converted to an encoded output byte sequence.

EncoderFallbackBuffer

提供緩衝區,允許後援處理常式在無法編碼輸入字元時,將替代字串傳回至編碼器。Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it cannot encode an input character.

EncoderFallbackException

當編碼器後援作業失敗時,所擲回的例外狀況。The exception that is thrown when an encoder fallback operation fails. 這個類別無法被繼承。This class cannot be inherited.

EncoderReplacementFallback

針對無法轉換為輸出位元組序列的輸入字元,提供失敗處理機制 (稱為後援)。Provides a failure handling mechanism, called a fallback, for an input character that cannot be converted to an output byte sequence. 此後援會使用使用者指定的取代字串,以取代原始輸入字元。The fallback uses a user-specified replacement string instead of the original input character. 這個類別無法被繼承。This class cannot be inherited.

EncoderReplacementFallbackBuffer

表示在無法為原始輸入字元編碼時,所使用的替代輸入字串。Represents a substitute input string that is used when the original input character cannot be encoded. 這個類別無法被繼承。This class cannot be inherited.

Encoding

表示字元編碼方式。Represents a character encoding.

EncodingInfo

提供有關編碼方式的基本資訊。Provides basic information about an encoding.

EncodingProvider

提供編碼提供者的基底類別,這個提供者提供特定平台無法使用的編碼方式。Provides the base class for an encoding provider, which supplies encodings that are unavailable on a particular platform.

StringBuilder

表示可變動的字元字串。Represents a mutable string of characters. 這個類別無法被繼承。This class cannot be inherited.

UnicodeEncoding

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

UTF32Encoding

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

UTF7Encoding

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

UTF8Encoding

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

結構

Rune

表示 Unicode 純量值 ( U+0000..U+D7FF ,或 U+E000..U+10FFFF )。Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive).

SpanRuneEnumerator

提供由包含 UTF-16 文字之範圍代表的 Rune 值的列舉程式。Provides an enumerator for the Rune values represented by a span containing UTF-16 text.

StringBuilder.ChunkEnumerator

支援簡單反覆處理 StringBuilder 執行個體區塊。Supports simple iteration over the chunks of a StringBuilder instance.

StringRuneEnumerator

提供由字串所代表之 Rune 值的列舉程式。Provides an enumerator for the Rune values represented by a string.

列舉

NormalizationForm

定義要執行的正規化類型。Defines the type of normalization to perform.

備註

編碼的類別主要是不同的編碼或字碼頁與 Unicode 編碼之間轉換。The encoding classes are primarily intended to convert between different encodings or code pages and a Unicode encoding. Encoding.Unicode (Utf-16) 編碼供內部.NET Framework,和Encoding.UTF8編碼通常用於儲存字元資料以確保跨電腦和文化特性的可攜性。Encoding.Unicode (UTF-16) encoding is used internally by the .NET Framework, and Encoding.UTF8 encoding is often used for storing character data to ensure portability across machines and cultures.

類別衍生自Encoding讓您選擇後援策略,決定如何處理無法編碼成位元組序列的字元或無法解碼為字元的位元組。The classes derived from Encoding enable you to choose a fallback strategy, which determines how characters that cannot be encoded into a sequence of bytes, or bytes that cannot be decoded into characters, are handled. 您可以選擇下列其中一項:You can choose one of the following:

  • 例外狀況後援。Exception fallback. 您可以選擇將擲回例外狀況資料錯誤藉由使用throwonerror旗標,可在部分類別建構函式或使用EncoderExceptionFallbackDecoderExceptionFallback類別。You can choose to throw exceptions on data errors either by using a throwonerror flag that is available in some class constructors or by using the EncoderExceptionFallback and DecoderExceptionFallback classes. 如果您關心的資料流的完整性,建議您使用擲回例外狀況。If you are concerned about the integrity of the data stream, throwing on an exception is recommended.

  • 取代後援。Replacement fallback. 您可以使用EncoderFallbackDecoderFallback類別,以無訊息方式變更某個字元,"?"或 Unicode replacement character (U + FFFD)。You can use the EncoderFallback and DecoderFallback classes to silently change a character to "?" or to the Unicode replacement character (U+FFFD).

  • 自動調整的後援。Best-fit fallback. 此選項對應中以其他編碼的字元編碼的字元。This option maps a character in one encoding to a character in another encoding. 自動調整的後援通常不建議使用,因為它會造成資料遺失,並且產生混淆,而且比簡單慢"?"字元取代項目。Best fit fallback is often not recommended because it can cause data loss and confusion, and is slower than simple "?" character replacements. 不過,ANSI 字碼頁的自動調整的行為是預設值。However, for ANSI code pages the best-fit behavior is the default.

StringBuilder類別專為單一字串執行廣泛的管理作業。The StringBuilder class is designed for operations that perform extensive manipulations on a single string. 不同於String類別,StringBuilder類別是可變動的並提供更佳的效能,串連或刪除字串時。Unlike the String class, the StringBuilder class is mutable and provides better performance when concatenating or deleting strings.

如需詳細資訊System.Text,請參閱 < .NET Framework 中的字元編碼For more information about System.Text, see Character Encoding in the .NET Framework .