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.
Ruft einen Decoder ab, der eine UTF-32-codierte Bytefolge in eine Unicode-Zeichensequenz konvertiert.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overrides Function GetDecoder As Decoder
'Usage
Dim instance As UnicodeEncoding
Dim returnValue As Decoder
returnValue = instance.GetDecoder
public override Decoder GetDecoder ()
public:
virtual Decoder^ GetDecoder () override
public Decoder GetDecoder ()
public override function GetDecoder () : Decoder
Rückgabewert
Ruft eine Decoder-Klasse ab, die eine UTF-32-codierte Bytefolge in eine Unicode-Zeichensequenz konvertiert.
Hinweise
Ähnlich wie die GetChars-Methode dieser Klasse konvertiert die Decoder.GetChars-Methode sequenzielle Blöcke von Bytes in sequenzielle Blöcke von Zeichen. Eine Decoder-Klasse erhält jedoch die Zustandsinformationen zwischen Aufrufen aufrecht, damit Blöcke umfassende Bytefolgen korrekt decodiert werden können. Die Decoder-Klasse behält nachfolgende Bytes am Ende von Datenblöcken bei und verwendet sie im nächsten Decodierungsvorgang. Deshalb empfehlen sich GetDecoder und GetEncoder für Netzwerkübertragungs- und Dateivorgänge, da diese Vorgänge oft mit Datenblöcken und nicht mit vollständigen Datenstreams arbeiten.
Wenn die Fehlererkennung in dieser Instanz aktiviert ist (d. h, der throwOnInvalidBytes-Parameter des Konstruktors wurde auf true festgelegt), wird die Fehlererkennung auch in der Decoder-Klasse aktiviert, die von dieser Methode zurückgegeben wird. Wenn die Fehlererkennung aktiviert ist und eine ungültige Folge gefunden wird, ist der Decoderzustand nicht definiert. Die Verarbeitung muss daher angehalten werden.
Beispiel
Im folgenden Codebeispiel wird eine Zeichenfolge mit einem Encoder und einem Decoder in ein Bytearray codiert, und anschließend werden die Bytes in ein Zeichenarray decodiert.
Imports System
Imports System.Text
Imports Microsoft.VisualBasic
Public Class SamplesUnicodeEncoding
Public Shared Sub Main()
' Get an encoder and a decoder from UnicodeEncoding.
Dim u16 As New UnicodeEncoding(False, True, True)
Dim myEnc As Encoder = u16.GetEncoder()
Dim myDec As Decoder = u16.GetDecoder()
' The characters to encode:
' 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)
Dim myChars() As Char = {"z"c, "a"c, ChrW(&H0306), ChrW(&H01FD), ChrW(&H03B2)}
Console.Write("The original characters : ")
Console.WriteLine(myChars)
' Encode the character array.
Dim iBC As Integer = myEnc.GetByteCount(myChars, 0, myChars.Length, True)
' NOTE: In Visual Basic, arrays contain one extra element by default.
' The following line creates an array with the exact number of elements required.
Dim myBytes(iBC - 1) As Byte
myEnc.GetBytes(myChars, 0, myChars.Length, myBytes, 0, True)
' Print the resulting bytes.
Console.Write("Using the encoder : ")
Dim i As Integer
For i = 0 To myBytes.Length - 1
Console.Write("{0:X2} ", myBytes(i))
Next i
Console.WriteLine()
' Decode the byte array back into an array of characters.
Dim iCC As Integer = myDec.GetCharCount(myBytes, 0, myBytes.Length, True)
' NOTE: In Visual Basic, arrays contain one extra element by default.
' The following line creates an array with the exact number of elements required.
Dim myDecodedChars(iCC - 1) As Char
myDec.GetChars(myBytes, 0, myBytes.Length, myDecodedChars, 0, True)
' Print the resulting characters.
Console.Write("Using the decoder : ")
Console.WriteLine(myDecodedChars)
End Sub 'Main
End Class 'SamplesUnicodeEncoding
'This code produces the following output. The question marks take the place of characters that cannot be displayed at the console.
'
'The original characters : za??ß
'Using the encoder : 7A 00 61 00 06 03 FD 01 B2 03
'Using the decoder : za??ß
using System;
using System.Text;
public class SamplesUnicodeEncoding {
public static void Main() {
// Get an encoder and a decoder from UnicodeEncoding.
UnicodeEncoding u16 = new UnicodeEncoding( false, true, true );
Encoder myEnc = u16.GetEncoder();
Decoder myDec = u16.GetDecoder();
// The characters to encode:
// 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)
char[] myChars = new char[5] { 'z', 'a', '\u0306', '\u01FD', '\u03B2' };
Console.Write( "The original characters : " );
Console.WriteLine( myChars );
// Encode the character array.
int iBC = myEnc.GetByteCount( myChars, 0, myChars.Length, true );
byte[] myBytes = new byte[iBC];
myEnc.GetBytes( myChars, 0, myChars.Length, myBytes, 0, true );
// Print the resulting bytes.
Console.Write( "Using the encoder : " );
for ( int i = 0; i < myBytes.Length; i++ )
Console.Write( "{0:X2} ", myBytes[i] );
Console.WriteLine();
// Decode the byte array back into an array of characters.
int iCC = myDec.GetCharCount( myBytes, 0, myBytes.Length, true );
char[] myDecodedChars = new char[iCC];
myDec.GetChars( myBytes, 0, myBytes.Length, myDecodedChars, 0, true );
// Print the resulting characters.
Console.Write( "Using the decoder : " );
Console.WriteLine( myDecodedChars );
}
}
/*
This code produces the following output. The question marks take the place of characters that cannot be displayed at the console.
The original characters : za??
Using the encoder : 7A 00 61 00 06 03 FD 01 B2 03
Using the decoder : za??
*/
using namespace System;
using namespace System::Text;
int main()
{
// Get an encoder and a decoder from UnicodeEncoding.
UnicodeEncoding^ u16 = gcnew UnicodeEncoding( false,true,true );
Encoder^ myEnc = u16->GetEncoder();
Decoder^ myDec = u16->GetDecoder();
// The characters to encode:
// 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)
array<Char>^myChars = gcnew array<Char>(5){
L'z',L'a',L'\u0306',L'\u01FD',L'\u03B2'
};
Console::Write( "The original characters : " );
Console::WriteLine( myChars );
// Encode the character array.
int iBC = myEnc->GetByteCount( myChars, 0, myChars->Length, true );
array<Byte>^myBytes = gcnew array<Byte>(iBC);
myEnc->GetBytes( myChars, 0, myChars->Length, myBytes, 0, true );
// Print the resulting bytes.
Console::Write( "Using the encoder : " );
for ( int i = 0; i < myBytes->Length; i++ )
Console::Write( "{0:X2} ", myBytes[ i ] );
Console::WriteLine();
// Decode the byte array back into an array of characters.
int iCC = myDec->GetCharCount( myBytes, 0, myBytes->Length, true );
array<Char>^myDecodedChars = gcnew array<Char>(iCC);
myDec->GetChars( myBytes, 0, myBytes->Length, myDecodedChars, 0, true );
// Print the resulting characters.
Console::Write( "Using the decoder : " );
Console::WriteLine( myDecodedChars );
}
/*
This code produces the following output. The question marks take the place of characters that cannot be displayed at the console.
The original characters : za??
Using the encoder : 7A 00 61 00 06 03 FD 01 B2 03
Using the decoder : za??
*/
import System.*;
import System.Text.*;
public class SamplesUnicodeEncoding
{
public static void main(String[] args)
{
// Get an encoder and a decoder from UnicodeEncoding.
UnicodeEncoding u16 = new UnicodeEncoding(false, true, true);
Encoder myEnc = u16.GetEncoder();
Decoder myDec = u16.GetDecoder();
// The characters to encode:
// 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)
char myChars[] = new char[] { 'z', 'a', '\u0306', '\u01FD', '\u03B2' };
Console.Write("The original characters : ");
Console.WriteLine(myChars);
// Encode the character array.
int iBC = myEnc.GetByteCount(myChars, 0, myChars.length, true);
ubyte myBytes[] = new ubyte[iBC];
myEnc.GetBytes(myChars, 0, myChars.length, myBytes, 0, true);
// Print the resulting bytes.
Console.Write("Using the encoder : ");
for(int i = 0; i < myBytes.length; i++) {
Console.Write("{0:X2} ", ((System.Byte)myBytes[i]).ToString("X2"));
}
Console.WriteLine();
// Decode the byte array back into an array of characters.
int iCC = myDec.GetCharCount(myBytes, 0, myBytes.length, true);
char myDecodedChars[] = new char[iCC];
myDec.GetChars(myBytes, 0, myBytes.length, myDecodedChars, 0, true);
// Print the resulting characters.
Console.Write("Using the decoder : ");
Console.WriteLine(myDecodedChars);
} //main
} //SamplesUnicodeEncoding
/*
This code produces the following output. The question marks take the place
of characters that cannot be displayed at the console.
The original characters : za??
Using the encoder : 7A 00 61 00 06 03 FD 01 B2 03
Using the decoder : za??
*/
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
UnicodeEncoding-Klasse
UnicodeEncoding-Member
System.Text-Namespace
Decoder-Klasse
GetChars
GetString
GetCharCount
GetEncoder