UTF7Encoding.GetDecoder メソッド

定義

UTF-7 でエンコードされたバイト シーケンスを Unicode 文字のシーケンスに変換するデコーダーを取得します。

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

返品

UTF-7 でエンコードされたバイト シーケンスを Unicode 文字のシーケンスに変換する Decoder

次のコード例では、 GetDecoder メソッドを使用してデコーダーを取得し、UTF-7 でエンコードされたバイトを一連の文字に変換する方法を示します。

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

注釈

Decoder.GetChars メソッドは、このクラスの GetChars メソッドと同様の方法で、バイトのシーケンシャル ブロックを文字のシーケンシャル ブロックに変換します。 ただし、 Decoder は、ブロックにまたがるバイト シーケンスを正しくデコードできるように、呼び出し間の状態情報を保持します。 Decoderでは、データ ブロックの末尾にある末尾のバイトも保持され、次のデコード操作で末尾のバイトが使用されます。 そのため、 GetDecoderGetEncoder は、ネットワーク転送とファイル操作に役立ちます。これらの操作は、多くの場合、完全なデータ ストリームではなくデータ ブロックを処理するためです。

適用対象

こちらもご覧ください