UTF7Encoding.GetDecoder Metódus

Definíció

Lekér egy dekódolót, amely UTF-7 kódolású bájtok sorozatát Unicode-karakterek sorozatává alakítja.

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

Válaszok

Az Decoder UTF-7 kódolású bájtok sorozatát Unicode-karakterek sorozatává konvertálja.

Példák

Az alábbi példakód bemutatja, hogyan használható a GetDecoder metódus egy dekóder beszerzésére az UTF-7 kódolású bájtok karaktersorozattá alakításához.

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

Megjegyzések

A Decoder.GetChars metódus a bájtok szekvenciális blokkjait szekvenciális karakterblokkokká alakítja az osztály metódusához GetChars hasonló módon. A hívások között azonban fenntartja az állapotinformációkat, Decoder hogy megfelelően dekódolhassa a blokkokra kiterjedő bájtsorozatokat. A Decoder záró bájtok az adatblokkok végén is megmaradnak, és a következő dekódolási műveletben a záró bájtokat használják. GetDecoder GetEncoder Ezért hasznos a hálózati átvitelhez és a fájlműveletekhez, mivel ezek a műveletek gyakran teljes adatfolyam helyett adatblokkokkal foglalkoznak.

A következőre érvényes:

Lásd még