UTF32Encoding::GetString Method (array<Byte>^, Int32, Int32)
Decodes a range of bytes from a byte array into a string.
Assembly: mscorlib (in mscorlib.dll)
public: virtual String^ GetString( array<unsigned char>^ bytes, int index, int count ) override
Parameters
- bytes
-
Type:
array<System::Byte>^
The byte array containing the sequence of bytes to decode.
- index
-
Type:
System::Int32
The index of the first byte to decode.
- count
-
Type:
System::Int32
The number of bytes to decode.
Return Value
Type: System::String^A string that contains the results of decoding the specified sequence of bytes.
| Exception | Condition |
|---|---|
| ArgumentNullException | bytes is null. |
| ArgumentOutOfRangeException | index or count is less than zero. -or- index and count do not denote a valid range in bytes. |
| ArgumentException | Error detection is enabled, and bytes contains an invalid sequence of bytes. |
| DecoderFallbackException | A fallback occurred (see Character Encoding in the .NET Framework for a complete explanation) -and- DecoderFallback is set to DecoderExceptionFallback. |
With error detection, an invalid sequence causes this method to throw a ArgumentException. Without error detection, invalid sequences are ignored, and no exception is thrown.
If the range of bytes to be decoded includes the byte order mark (BOM), and the byte array was returned by a method of a non-BOM aware type, the character U+FFFE is included in the character array returned by this method. You can remove it by calling the String::TrimStart method.
Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application should use the Decoder or the Encoder provided by the GetDecoder method or the GetEncoder method, respectively.
The following example encodes a string into two arrays arrays of bytes, one in little-endian order and the other in big-endian order. It then decodes the bytes back into a string.
The following example initializes an array by calling the GetByteCount method to determine exactly how many bytes are required for an encoded string and then adding the size of the byte order mark (BOM). The example then calls the GetPreamble method to store the BOM to the array before calling the GetBytes method to store the encoded bytes to the array. The example then calls the GetString method to decode the string.
Available since 10
.NET Framework
Available since 2.0
Note that in this case the decoded string differs from the original string, since it begins with a 32-bit byte order mark U+FFFE U+0000. This means that the two strings will compare as unequal, and that if the string is output, the BOM will be displayed as the replacement character "?".