Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Text.​Encoding

Assembly: System.Runtime

Inheritance: object → Encoding

Implemented Interfaces

Represents a character encoding.

Properties

public static Encoding
ASCII
Gets an encoding for the ASCII (7-bit) character set.
public static Encoding
BigEndianUnicode
Gets an encoding for the UTF-16 format that uses the big endian byte order.
public string
BodyName
When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags.
public int
CodePage
When overridden in a derived class, gets the code page identifier of the current <see cref="T:System.Text.Encoding" /> .
DecoderFallback
Gets or sets the <see cref="T:System.Text.DecoderFallback" /> object for the current <see cref="T:System.Text.Encoding" /> object.
public static Encoding
Default
Gets the default encoding for this .NET implementation.
EncoderFallback
Gets or sets the <see cref="T:System.Text.EncoderFallback" /> object for the current <see cref="T:System.Text.Encoding" /> object.
public string
EncodingName
When overridden in a derived class, gets the human-readable description of the current encoding.
public string
HeaderName
When overridden in a derived class, gets a name for the current encoding that can be used with mail agent header tags.
public bool
IsBrowserDisplay
When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for displaying content.
public bool
IsBrowserSave
When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for saving content.
public bool
IsMailNewsDisplay
When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
public bool
IsMailNewsSave
When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
public bool
IsReadOnly
When overridden in a derived class, gets a value indicating whether the current encoding is read-only.
public bool
IsSingleByte
When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points.
public static Encoding
Latin1
Gets an encoding for the Latin1 character set (ISO-8859-1).
public ReadOnlySpan<​byte>
Preamble
When overridden in a derived class, returns a span containing the sequence of bytes that specifies the encoding used.
public static Encoding
Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
public static Encoding
UTF32
Gets an encoding for the UTF-32 format using the little endian byte order.
public static Encoding
UTF7
Gets an encoding for the UTF-7 format.
public static Encoding
UTF8
Gets an encoding for the UTF-8 format.
public string
WebName
When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
public int
WindowsCodePage
When overridden in a derived class, gets the Windows operating system code page that most closely corresponds to the current encoding.

Methods

public object
Clone​()
When overridden in a derived class, creates a shallow copy of the current <see cref="T:System.Text.Encoding" /> object.
Returns A copy of the current <see cref="T:System.Text.Encoding" /> object.
public static byte[]
Convert​(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
Converts an entire byte array from one encoding to another.
Returns An array of type <see cref="T:System.Byte" /> containing the results of converting <paramref name="bytes" /> from <paramref name="srcEncoding" /> to <paramref name="dstEncoding" /> .
srcEncoding The encoding format of <paramref name="bytes" /> .
dstEncoding The target encoding format.
bytes The bytes to convert.
public static byte[]
Convert​(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count)
Converts a range of bytes in a byte array from one encoding to another.
Returns An array of type <see cref="T:System.Byte" /> containing the result of converting a range of bytes in <paramref name="bytes" /> from <paramref name="srcEncoding" /> to <paramref name="dstEncoding" /> .
srcEncoding The encoding of the source array, <paramref name="bytes" /> .
dstEncoding The encoding of the output array.
bytes The array of bytes to convert.
index The index of the first element of <paramref name="bytes" /> to convert.
count The number of bytes to convert.
public static IO.​Stream
CreateTranscodingStream​(IO.​Stream innerStream, Encoding innerStreamEncoding, Encoding outerStreamEncoding, bool leaveOpen = false)
Creates a <see cref="T:System.IO.Stream" /> that serves to transcode data between an inner <see cref="T:System.Text.Encoding" /> and an outer <see cref="T:System.Text.Encoding" /> , similar to <see cref="M:System.Text.Encoding.Convert(System.Text.Encoding,System.Text.Encoding,System.Byte[])" /> .
Returns A stream that transcodes the contents of <paramref name="innerStream" /> as <paramref name="outerStreamEncoding" /> .
innerStream The stream to wrap.
innerStreamEncoding The encoding associated with <paramref name="innerStream" /> .
outerStreamEncoding The encoding associated with the <see cref="T:System.IO.Stream" /> that's returned by this method.
leaveOpen <see langword="true" /> if disposing the <see cref="T:System.IO.Stream" /> returned by this method should <em>not</em> dispose <paramref name="innerStream" /> .
public bool
Equals​(object value)
Determines whether the specified <see cref="T:System.Object" /> is equal to the current instance.
Returns <see langword="true" /> if <paramref name="value" /> is an instance of <see cref="T:System.Text.Encoding" /> and is equal to the current instance; otherwise, <see langword="false" /> .
value The <see cref="T:System.Object" /> to compare with the current instance.
public int
GetByteCount​(Char* chars, int count)
When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer.
Returns The number of bytes produced by encoding the specified characters.
chars A pointer to the first character to encode.
count The number of characters to encode.
public int
GetByteCount​(char[] chars)
When overridden in a derived class, calculates the number of bytes produced by encoding all the characters in the specified character array.
Returns The number of bytes produced by encoding all the characters in the specified character array.
chars The character array containing the characters to encode.
public int
GetByteCount​(char[] chars, int index, int count)
When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array.
Returns The number of bytes produced by encoding the specified characters.
chars The character array containing the set of characters to encode.
index The index of the first character to encode.
count The number of characters to encode.
public int
GetByteCount​(ReadOnlySpan<​char> chars)
When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified character span.
Returns The number of bytes produced by encoding the specified character span.
chars The span of characters to encode.
public int
GetByteCount​(string s)
When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified string.
Returns The number of bytes produced by encoding the specified characters.
s The string containing the set of characters to encode.
public int
GetByteCount​(string s, int index, int count)
When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified string.
Returns The number of bytes produced by encoding the string.
s The string containing the set of characters to encode.
index The index of the first character to encode.
count The number of characters to encode.
public int
GetBytes​(Char* chars, int charCount, Byte* bytes, int byteCount)
When overridden in a derived class, encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer.
Returns The actual number of bytes written at the location indicated by the <paramref name="bytes" /> parameter.
chars A pointer to the first character to encode.
charCount The number of characters to encode.
bytes A pointer to the location at which to start writing the resulting sequence of bytes.
byteCount The maximum number of bytes to write.
public byte[]
GetBytes​(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into a sequence of bytes.
Returns A byte array containing the results of encoding the specified set of characters.
chars The character array containing the characters to encode.
public byte[]
GetBytes​(char[] chars, int index, int count)
When overridden in a derived class, encodes a set of characters from the specified character array into a sequence of bytes.
Returns A byte array containing the results of encoding the specified set of characters.
chars The character array containing the set of characters to encode.
index The index of the first character to encode.
count The number of characters to encode.
public int
GetBytes​(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
When overridden in a derived class, encodes a set of characters from the specified character array into the specified byte array.
Returns The actual number of bytes written into <paramref name="bytes" /> .
chars The character array containing the set of characters to encode.
charIndex The index of the first character to encode.
charCount The number of characters to encode.
bytes The byte array to contain the resulting sequence of bytes.
byteIndex The index at which to start writing the resulting sequence of bytes.
public int
GetBytes​(ReadOnlySpan<​char> chars, Span<​byte> bytes)
When overridden in a derived class, encodes into a span of bytes a set of characters from the specified read-only span.
Returns The number of encoded bytes.
chars The span containing the set of characters to encode.
bytes The byte span to hold the encoded bytes.
public byte[]
GetBytes​(string s)
When overridden in a derived class, encodes all the characters in the specified string into a sequence of bytes.
Returns A byte array containing the results of encoding the specified set of characters.
s The string containing the characters to encode.
public byte[]
GetBytes​(string s, int index, int count)
When overridden in a derived class, encodes into an array of bytes the number of characters specified by <paramref name="count" /> in the specified string, starting from the specified <paramref name="index" /> .
Returns A byte array containing the results of encoding the specified set of characters.
s The string containing the characters to encode.
index The index inside the string to start the encoding from.
count The number of characters to encode.
public int
GetBytes​(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array.
Returns The actual number of bytes written into <paramref name="bytes" /> .
s The string containing the set of characters to encode.
charIndex The index of the first character to encode.
charCount The number of characters to encode.
bytes The byte array to contain the resulting sequence of bytes.
byteIndex The index at which to start writing the resulting sequence of bytes.
public int
GetCharCount​(Byte* bytes, int count)
When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.
Returns The number of characters produced by decoding the specified sequence of bytes.
bytes A pointer to the first byte to decode.
count The number of bytes to decode.
public int
GetCharCount​(byte[] bytes)
When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array.
Returns The number of characters produced by decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
public int
GetCharCount​(byte[] bytes, int index, int count)
When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
Returns The number of characters produced by decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
index The index of the first byte to decode.
count The number of bytes to decode.
public int
GetCharCount​(ReadOnlySpan<​byte> bytes)
When overridden in a derived class, calculates the number of characters produced by decoding the provided read-only byte span.
Returns The number of characters produced by decoding the byte span.
bytes A read-only byte span to decode.
public int
GetChars​(Byte* bytes, int byteCount, Char* chars, int charCount)
When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer.
Returns The actual number of characters written at the location indicated by the <paramref name="chars" /> parameter.
bytes A pointer to the first byte to decode.
byteCount The number of bytes to decode.
chars A pointer to the location at which to start writing the resulting set of characters.
charCount The maximum number of characters to write.
public char[]
GetChars​(byte[] bytes)
When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters.
Returns A character array containing the results of decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
public char[]
GetChars​(byte[] bytes, int index, int count)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters.
Returns A character array containing the results of decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
index The index of the first byte to decode.
count The number of bytes to decode.
public int
GetChars​(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array into the specified character array.
Returns The actual number of characters written into <paramref name="chars" /> .
bytes The byte array containing the sequence of bytes to decode.
byteIndex The index of the first byte to decode.
byteCount The number of bytes to decode.
chars The character array to contain the resulting set of characters.
charIndex The index at which to start writing the resulting set of characters.
public int
GetChars​(ReadOnlySpan<​byte> bytes, Span<​char> chars)
When overridden in a derived class, decodes all the bytes in the specified read-only byte span into a character span.
Returns The actual number of characters written at the span indicated by the <paramref name="chars" /> parameter.
bytes A read-only span containing the sequence of bytes to decode.
chars The character span receiving the decoded bytes.
public Decoder
GetDecoder​()
When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into a sequence of characters.
Returns A <see cref="T:System.Text.Decoder" /> that converts an encoded sequence of bytes into a sequence of characters.
public Encoder
GetEncoder​()
When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters into an encoded sequence of bytes.
Returns A <see cref="T:System.Text.Encoder" /> that converts a sequence of Unicode characters into an encoded sequence of bytes.
public static Encoding
GetEncoding​(int codepage)
Returns the encoding associated with the specified code page identifier.
Returns The encoding that is associated with the specified code page.
codepage The code page identifier of the preferred encoding. For a list of possible values, see <see cref="T:System.Text.Encoding" /> . -or- 0 (zero), to use the default encoding.
public static Encoding
GetEncoding​(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Returns the encoding associated with the specified code page identifier. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.
Returns The encoding that is associated with the specified code page.
codepage The code page identifier of the preferred encoding. For a list of possible values, see <see cref="T:System.Text.Encoding" /> . -or- 0 (zero), to use the default encoding.
encoderFallback An object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallback An object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
public static Encoding
GetEncoding​(string name)
Returns the encoding associated with the specified code page name.
Returns The encoding associated with the specified code page.
name The code page name of the preferred encoding. Any value returned by the <see cref="P:System.Text.Encoding.WebName" /> property is valid. For a list of possible values, see <see cref="T:System.Text.Encoding" /> .
public static Encoding
GetEncoding​(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
Returns the encoding associated with the specified code page name. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.
Returns The encoding that is associated with the specified code page.
name The code page name of the preferred encoding. Any value returned by the <see cref="P:System.Text.Encoding.WebName" /> property is valid. Possible values are listed in the Name column of the table that appears in the <see cref="T:System.Text.Encoding" /> class topic.
encoderFallback An object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallback An object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
public static EncodingInfo[]
GetEncodings​()
Returns an array that contains all encodings.
Returns An array that contains all encodings.
public int
GetHashCode​()
Returns the hash code for the current instance.
Returns The hash code for the current instance.
public int
GetMaxByteCount​(int charCount)
When overridden in a derived class, calculates the maximum number of bytes produced by encoding the specified number of characters.
Returns The maximum number of bytes produced by encoding the specified number of characters.
charCount The number of characters to encode.
public int
GetMaxCharCount​(int byteCount)
When overridden in a derived class, calculates the maximum number of characters produced by decoding the specified number of bytes.
Returns The maximum number of characters produced by decoding the specified number of bytes.
byteCount The number of bytes to decode.
public byte[]
GetPreamble​()
When overridden in a derived class, returns a sequence of bytes that specifies the encoding used.
Returns A byte array containing a sequence of bytes that specifies the encoding used. -or- A byte array of length zero, if a preamble is not required.
public string
GetString​(Byte* bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified address into a string.
Returns A string that contains the results of decoding the specified sequence of bytes.
bytes A pointer to a byte array.
byteCount The number of bytes to decode.
public string
GetString​(byte[] bytes)
When overridden in a derived class, decodes all the bytes in the specified byte array into a string.
Returns A string that contains the results of decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
public string
GetString​(byte[] bytes, int index, int count)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a string.
Returns A string that contains the results of decoding the specified sequence of bytes.
bytes The byte array containing the sequence of bytes to decode.
index The index of the first byte to decode.
count The number of bytes to decode.
public string
GetString​(ReadOnlySpan<​byte> bytes)
When overridden in a derived class, decodes all the bytes in the specified byte span into a string.
Returns A string that contains the decoded bytes from the provided read-only span.
bytes A read-only byte span to decode to a Unicode string.
public bool
IsAlwaysNormalized​()
Gets a value indicating whether the current encoding is always normalized, using the default normalization form.
Returns <see langword="true" /> if the current <see cref="T:System.Text.Encoding" /> is always normalized; otherwise, <see langword="false" /> . The default is <see langword="false" /> .
public bool
IsAlwaysNormalized​(NormalizationForm form)
When overridden in a derived class, gets a value indicating whether the current encoding is always normalized, using the specified normalization form.
Returns <see langword="true" /> if the current <see cref="T:System.Text.Encoding" /> object is always normalized using the specified <see cref="T:System.Text.NormalizationForm" /> value; otherwise, <see langword="false" /> . The default is <see langword="false" /> .
form One of the <see cref="T:System.Text.NormalizationForm" /> values.
public static void
RegisterProvider​(EncodingProvider provider)
Registers an encoding provider.
provider A subclass of <see cref="T:System.Text.EncodingProvider" /> that provides access to additional character encodings.
public bool
TryGetBytes​(ReadOnlySpan<​char> chars, Span<​byte> bytes, Int32& bytesWritten)
public bool
TryGetChars​(ReadOnlySpan<​byte> bytes, Span<​char> chars, Int32& charsWritten)
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.