Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der UTF7Encoding-Klasse. Ein Parameter gibt an, ob optionale Zeichen zulässig sind.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
allowOptionals As Boolean _
)
'Usage
Dim allowOptionals As Boolean
Dim instance As New UTF7Encoding(allowOptionals)
public UTF7Encoding (
bool allowOptionals
)
public:
UTF7Encoding (
bool allowOptionals
)
public UTF7Encoding (
boolean allowOptionals
)
public function UTF7Encoding (
allowOptionals : boolean
)
Parameter
- allowOptionals
true, um anzugeben, dass optionale Zeichen zulässig sind, andernfalls false.
Hinweise
Wenn eine Instanz optionale Zeichen zulässt, werden Unicode-Codepunkte nicht mit einem geänderten Base-64-Zeichen, sondern mit einem entsprechenden optionalen Zeichen codiert. Die optionalen Zeichen sind: Ausrufezeichen ('!'), umgekehrter Schrägstrich ('\'), senkrechter Strich ('|'), doppelte Anführungszeichen ('"'), Nummernzeichen ('#'), Dollarzeichen ('$'), Prozentzeichen ('%'), kaufmännisches Und-Zeichen ('&'), Sternchen ('*'), Semikolon (';'), spitze Klammer links ('<'), spitze Klammer rechts ('>'), geschweifte Klammer links ('{'), geschweifte Klammer rechts ('}'), eckige Klammer links ('['), eckige Klammer rechts (']'), Gleichheitszeichen ('='), @-Zeichen ('@'), Zirkumflex-Akzent ('^'), Unterstrich ('_') und Gravis-Akzent ('`').
Warnung
UTF7Encoding stellt keine Fehlererkennung bereit. Aus Sicherheitsgründen wird empfohlen, UTF8Encoding, UnicodeEncoding oder UTF32Encoding zu verwenden und die Fehlererkennung zu aktivieren.
Beispiel
Das folgende Beispiel veranschaulicht die Erstellung einer neuen UTF7Encoding-Instanz, die optionale Zeichen zulässt.
Imports System
Imports System.Text
Class UTF7EncodingExample
Public Shared Sub Main()
' A few optional characters.
Dim chars As String = "!@#$"
' The default Encoding does not allow optional characters.
' Alternate byte values are used.
Dim utf7 As New UTF7Encoding()
Dim bytes1 As Byte() = 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.
Dim utf7AllowOptionals As New UTF7Encoding(True)
Dim bytes2 As Byte() = utf7AllowOptionals.GetBytes(chars)
Console.WriteLine("UTF7 Encoding with optional characters allowed:")
ShowArray(bytes2)
' Convert back to characters.
Console.WriteLine("Characters:")
ShowArray(utf7AllowOptionals.GetChars(bytes2))
End Sub 'Main
Public Shared Sub ShowArray(theArray As Array)
Dim o As Object
For Each o In theArray
Console.Write("[{0}]", o)
Next o
Console.WriteLine()
End Sub 'ShowArray
End Class 'UTF7EncodingExample
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
// A few optional characters.
string chars = "!@#$";
// The default Encoding does not allow optional characters.
// Alternate byte values are used.
UTF7Encoding utf7 = new UTF7Encoding();
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 = new UTF7Encoding(true);
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));
}
public static void ShowArray(Array theArray) {
foreach (Object o in theArray) {
Console.Write("[{0}]", o);
}
Console.WriteLine();
}
}
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 ) );
}
import System.*;
import System.Text.*;
class EncodingExample
{
public static void main(String[] args)
{
// A few optional characters.
String chars = "!@#$";
// The default Encoding does not allow optional characters.
// Alternate byte values are used.
UTF7Encoding utf7 = new UTF7Encoding();
ubyte 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 = new UTF7Encoding(true);
ubyte 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));
} //main
public static void ShowArray(Array theArray)
{
Object obj = null;
for(int iCtr = 0; iCtr < theArray.get_Length(); iCtr++) {
obj = theArray.get_Item(iCtr);
Console.Write("[{0}]", obj);
}
Console.WriteLine();
} //ShowArray
} //EncodingExample
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
UTF7Encoding-Klasse
UTF7Encoding-Member
System.Text-Namespace