System.Text 命名空间

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 替换字符 (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 .