1/27
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Encoding
A class in the System.Text namespace that represents character encodings and provides operations for converting between Unicode characters and encoded byte sequences. Domain: C# → .NET → System.Text → Character Encoding
Encoding.UTF8
Gets a UTF-8 encoding, which represents Unicode characters using a variable number of bytes.
Encoding.Unicode
Gets a UTF-16 little-endian encoding, where text is represented using 16-bit code units.
Encoding.BigEndianUnicode
Gets a UTF-16 big-endian encoding, which stores the most significant byte of each 16-bit code unit first.
Encoding.UTF32
Gets a UTF-32 little-endian encoding, which represents Unicode code points using 32-bit code units.
Encoding.ASCII
Gets an ASCII encoding, which represents the 128 standard ASCII characters.
Encoding.Latin1
Gets the Latin-1 encoding, which directly represents the first 256 Unicode code points using one byte each.
byte[] bytes = Encoding.UTF8.GetBytes(text);
Converts the characters in text into a byte array using UTF-8 encoding.
string text = Encoding.UTF8.GetString(bytes);
Decodes a UTF-8 encoded byte array into a C# string.
int byteCount = Encoding.UTF8.GetByteCount(text);
Calculates how many bytes are required to encode the specified text using UTF-8.
int charCount = Encoding.UTF8.GetCharCount(bytes);
Calculates how many UTF-16 char values will result from decoding the specified UTF-8 bytes.
char[] chars = Encoding.UTF8.GetChars(bytes);
Decodes a UTF-8 byte array into an array of characters.
int maxBytes = Encoding.UTF8.GetMaxByteCount(charCount);
Calculates the maximum possible number of bytes that may be required to encode a specified number of characters.
int maxChars = Encoding.UTF8.GetMaxCharCount(byteCount);
Calculates the maximum possible number of characters that may result from decoding a specified number of bytes.
Encoding encoding = Encoding.GetEncoding("utf-8");
Gets an Encoding object for an encoding specified by name.
Encoding.Default
Gets the default encoding for the current .NET environment.
Unrepresentable Character
A character that cannot be represented by a particular character encoding, such as many Unicode characters when using ASCII.
Encoding encoding = Encoding.GetEncoding("ASCII", EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
Configures the encoding to throw an exception when a character cannot be represented instead of silently replacing it.
Encoder
A stateful object that converts characters into bytes while preserving conversion state when text is processed in multiple chunks.
Decoder
A stateful object that converts encoded bytes into characters while preserving conversion state when byte data is processed in multiple chunks.
Encoding Preamble
A sequence of bytes that may appear at the beginning of encoded data to provide information about its character encoding.
byte[] preamble = encoding.GetPreamble();
Returns the sequence of bytes representing the preamble associated with the specified encoding.
read-only sequence
Encoding Preamble Property provides the preamble associated with an encoding as a ________________ of bytes. It can be used to inspect whether that particular encoding supplies a preamble.
Byte Order Mark (BOM)
A byte sequence that may appear at the beginning of Unicode-encoded text to identify its encoding and, where relevant, its byte order.
Unicode Code Point
A numerical value assigned to a Unicode character or text element, conventionally written in a form such as U+0041 for A.
UTF-16 Code Unit
A 16-bit unit used by UTF-16 to represent Unicode text; some Unicode code points require one code unit, while others require two.
Surrogate Pair
Two UTF-16 code units—a high surrogate followed by a low surrogate—used together to represent a Unicode code point outside the Basic Multilingual Plane.
char
A ____ in C# represents one UTF-16 code unit, not necessarily one complete Unicode character. Therefore, some Unicode characters require 2 of these values.