Encoding
Struct · namespace System
struct EncodingConversion between strings (always UTF-8 in memory) and raw bytes.
var bytes = Encoding.UTF8().GetBytes("héllo");if (Encoding.ASCII().GetString(bytes) is string text) { ... }Static methods
Section titled “Static methods”| Name | Description |
|---|---|
UTF8 |
The UTF-8 encoding. |
ASCII |
The ASCII encoding. |
static Encoding UTF8()The UTF-8 encoding.
static Encoding ASCII()The ASCII encoding.
Methods
Section titled “Methods”| Name | Description |
|---|---|
Name |
The name of the encoding: "UTF-8" or "ASCII". |
GetBytes |
The bytes of s in this encoding. |
GetByteCount |
The number of bytes Encoding.GetBytes returns for s. |
GetString |
Decodes all of bytes into a string. |
string Name()The name of the encoding: "UTF-8" or "ASCII".
GetBytes
Section titled “GetBytes”uint8[] GetBytes(StringSlice s)The bytes of s in this encoding. UTF-8: the bytes of the string as they are. ASCII: one byte per character;
characters above 127 become ?.
GetByteCount
Section titled “GetByteCount”int GetByteCount(StringSlice s)The number of bytes Encoding.GetBytes returns for s.
GetString
Section titled “GetString”EncodingError<string> GetString(uint8[] bytes)Decodes all of bytes into a string.
Errors
EncodingError.NotAscii: a byte above 127 for ASCII.EncodingError.InvalidUtf8: malformed UTF-8.
EncodingError<string> GetString(uint8[] bytes, int start, int count)Decodes count bytes of bytes, starting at start, into a string.
Errors
EncodingError.OutOfBounds: the range is not inside ofbytes.EncodingError.NotAscii: a byte above 127 for ASCII.EncodingError.InvalidUtf8: malformed UTF-8.