UTF7Encoding Constructor (Boolean)
Initializes a new instance of the UTF7Encoding class. A parameter specifies whether to allow optional characters.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- allowOptionals
-
Type:
System::Boolean
true to specify that optional characters are allowed; otherwise, false.
If an instance allows optional characters, Unicode code points are encoded with a corresponding optional character instead of a modified base 64 character. The optional characters are exclamation point ("!"), backward slash ("\"), vertical line ("|"), double quote ("""), number sign ("#"), dollar sign ("$"), percent sign ("%"), ampersand ("&"), asterisk ("*"), semicolon (";"), left angle bracket ("<"), right angle bracket (">"), left curly bracket ("{"), right curly bracket ("}"), left square bracket ("["), right square bracket ("]"), equal sign ("="), at sign ("@"), circumflex accent ("^"), underscore ("_"), and grave accent ("`").
Note |
|---|
UTF7Encoding does not provide error detection. For security reasons, your applications are recommended to use UTF8Encoding, UnicodeEncoding, or UTF32Encoding and enable error detection. |
The following code example demonstrates how to create a new UTF7Encoding instance that allows optional characters.
using namespace System; using namespace System::Text; using namespace System::Collections; void ShowArray( Array^ theArray ) { IEnumerator^ myEnum = theArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ o = safe_cast<Object^>(myEnum->Current); Console::Write( "[{0}]", o ); } Console::WriteLine(); } int main() { // A few optional characters. String^ chars = "!@#$"; // The default Encoding does not allow optional characters. // Alternate Byte values are used. UTF7Encoding^ utf7 = gcnew UTF7Encoding; array<Byte>^bytes1 = utf7->GetBytes( chars ); Console::WriteLine( "Default UTF7 Encoding:" ); ShowArray( bytes1 ); // Convert back to characters. Console::WriteLine( "Characters:" ); ShowArray( utf7->GetChars( bytes1 ) ); // Now, allow optional characters. // Optional characters are encoded with their normal code points. UTF7Encoding^ utf7AllowOptionals = gcnew UTF7Encoding( true ); array<Byte>^bytes2 = utf7AllowOptionals->GetBytes( chars ); Console::WriteLine( "UTF7 Encoding with optional characters allowed:" ); ShowArray( bytes2 ); // Convert back to characters. Console::WriteLine( "Characters:" ); ShowArray( utf7AllowOptionals->GetChars( bytes2 ) ); }
Available since 10
.NET Framework
Available since 1.1
