UTF7Encoding.GetDecoder Método

Definición

Obtiene un descodificador que convierte una secuencia de bytes codificada en UTF-7 en una secuencia de caracteres Unicode.Obtains a decoder that converts a UTF-7 encoded sequence of bytes into a sequence of Unicode characters.

public:
 override System::Text::Decoder ^ GetDecoder();
public override System.Text.Decoder GetDecoder ();
override this.GetDecoder : unit -> System.Text.Decoder
Public Overrides Function GetDecoder () As Decoder

Devoluciones

Decoder

Objeto Decoder que convierte una secuencia de bytes codificada en UTF-7 en una secuencia de caracteres Unicode.A Decoder that converts a UTF-7 encoded sequence of bytes into a sequence of Unicode characters.

Ejemplos

En el ejemplo de código siguiente se muestra cómo utilizar el GetDecoder método para obtener un descodificador que convierta los bytes codificados en UTF-7 en una secuencia de caracteres.The following code example demonstrates how to use the GetDecoder method to obtain a decoder to convert the UTF-7 encoded bytes into a sequence of characters.

using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
   array<Char>^chars;
   array<Byte>^bytes = {99,43,65,119,67,103,111,65,45};
   Decoder^ utf7Decoder = Encoding::UTF7->GetDecoder();
   int charCount = utf7Decoder->GetCharCount( bytes, 0, bytes->Length );
   chars = gcnew array<Char>(charCount);
   int charsDecodedCount = utf7Decoder->GetChars( bytes, 0, bytes->Length, chars, 0 );
   Console::WriteLine( "{0} characters used to decode bytes.", charsDecodedCount );
   Console::Write( "Decoded chars: " );
   IEnumerator^ myEnum = chars->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Char c = safe_cast<Char>(myEnum->Current);
      Console::Write( "[{0}]", c.ToString() );
   }

   Console::WriteLine();
}

using System;
using System.Text;

class UTF7EncodingExample {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {
            99, 43, 65, 119, 67, 103, 111, 65, 45
        };

        Decoder utf7Decoder = Encoding.UTF7.GetDecoder();

        int charCount = utf7Decoder.GetCharCount(bytes, 0, bytes.Length);
        chars = new Char[charCount];
        int charsDecodedCount = utf7Decoder.GetChars(bytes, 0, bytes.Length, chars, 0);

        Console.WriteLine(
            "{0} characters used to decode bytes.", charsDecodedCount
        );

        Console.Write("Decoded chars: ");
        foreach (Char c in chars) {
            Console.Write("[{0}]", c);
        }
        Console.WriteLine();
    }
}
Imports System.Text

Class UTF7EncodingExample
    
    Public Shared Sub Main()
        Dim chars() As Char
        Dim bytes() As Byte = {99, 43, 65, 119, 67, 103, 111, 65, 45}
        
        Dim utf7Decoder As Decoder = Encoding.UTF7.GetDecoder()
        
        Dim charCount As Integer = utf7Decoder.GetCharCount(bytes, 0, bytes.Length)
        chars = New Char(charCount - 1) {}
        Dim charsDecodedCount As Integer = utf7Decoder.GetChars(bytes, 0, bytes.Length, chars, 0)
        
        Console.WriteLine("{0} characters used to decode bytes.", charsDecodedCount)
        
        Console.Write("Decoded chars: ")
        Dim c As Char
        For Each c In  chars
            Console.Write("[{0}]", c)
        Next c
        Console.WriteLine()
    End Sub
End Class

Comentarios

El Decoder.GetChars método convierte bloques secuenciales de bytes en bloques secuenciales de caracteres, de manera similar al GetChars método de esta clase.The Decoder.GetChars method converts sequential blocks of bytes into sequential blocks of characters, in a manner similar to the GetChars method of this class. Sin embargo, Decoder mantiene la información de estado entre llamadas para que pueda descodificar correctamente las secuencias de bytes que abarcan bloques.However, a Decoder maintains state information between calls so it can correctly decode byte sequences that span blocks. DecoderTambién conserva los bytes finales al final de los bloques de datos y usa los bytes finales en la siguiente operación de descodificación.The Decoder also preserves trailing bytes at the end of data blocks and uses the trailing bytes in the next decoding operation. Por lo tanto, GetDecoder y GetEncoder son útiles para la transmisión de red y las operaciones de archivos, ya que estas operaciones suelen tratar con bloques de datos en lugar de con una secuencia de datos completa.Therefore, GetDecoder and GetEncoder are useful for network transmission and file operations, because those operations often deal with blocks of data instead of a complete data stream.

Se aplica a

Consulte también