UTF32Encoding Constructor (Boolean, Boolean, Boolean)
Initializes a new instance of the UTF32Encoding class. Parameters specify whether to use the big endian byte order, whether to provide a Unicode byte order mark, and whether to throw an exception when an invalid encoding is detected.
Assembly: mscorlib (in mscorlib.dll)
public: UTF32Encoding( bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters )
Parameters
- bigEndian
-
Type:
System::Boolean
true to use the big endian byte order (most significant byte first), or false to use the little endian byte order (least significant byte first).
- byteOrderMark
-
Type:
System::Boolean
true to specify that a Unicode byte order mark is provided; otherwise, false.
- throwOnInvalidCharacters
-
Type:
System::Boolean
true to specify that an exception should be thrown when an invalid encoding is detected; otherwise, false.
If throwOnInvalidCharacters is true, a method that detects an invalid byte sequence throws System::ArgumentException. Otherwise, the method does not throw an exception, and the invalid sequence is ignored.
Note |
|---|
For security reasons, you should enable error detection by calling the UTF32Encoding(Boolean, Boolean, Boolean) constructor and setting its throwOnInvalidCharacters argument to true. |
The following example demonstrates the behavior of UTF32Encoding, both with error detection enabled and without.
using namespace System; using namespace System::Text; void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ); int main() { // Create an instance of UTF32Encoding using little-endian byte order. // This will be used for encoding. UTF32Encoding^ u32LE = gcnew UTF32Encoding( false,true ); // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without. // These will be used for decoding. UTF32Encoding^ u32withED = gcnew UTF32Encoding( true,true,true ); UTF32Encoding^ u32noED = gcnew UTF32Encoding( true,true,false ); // Create byte arrays from the same string containing the following characters: // Latin Small Letter Z (U+007A) // Latin Small Letter A (U+0061) // Combining Breve (U+0306) // Latin Small Letter AE With Acute (U+01FD) // Greek Small Letter Beta (U+03B2) String^ myStr = L"za\u0306\u01FD\u03B2\xD8FF\xDCFF"; // Encode the string using little-endian byte order. array<Byte>^myBytes = gcnew array<Byte>(u32LE->GetByteCount( myStr )); u32LE->GetBytes( myStr, 0, myStr->Length, myBytes, 0 ); // Decode the byte array with error detection. Console::WriteLine( "Decoding with error detection:" ); PrintDecodedString( myBytes, u32withED ); // Decode the byte array without error detection. Console::WriteLine( "Decoding without error detection:" ); PrintDecodedString( myBytes, u32noED ); } // Decode the bytes and display the string. void PrintDecodedString( array<Byte>^bytes, Encoding^ enc ) { try { Console::WriteLine( " Decoded string: {0}", enc->GetString( bytes, 0, bytes->Length ) ); } catch ( System::ArgumentException^ e ) { Console::WriteLine( e ); } Console::WriteLine(); }
Available since 10
.NET Framework
Available since 2.0
