UTF7Encoding.GetEncoder Yöntem

Tanım

Unicode karakter dizisini UTF-7 kodlanmış bayt dizisine dönüştüren bir kodlayıcı alır.

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

Döndürülenler

Unicode Encoder karakter dizisini UTF-7 ile kodlanmış bayt dizisine dönüştüren bir.

Örnekler

Aşağıdaki kod örneği, bir karakter dizisini GetEncoder UTF-7 ile kodlanmış bayt dizisine dönüştürmek üzere bir kodlayıcı almak için yönteminin nasıl kullanılacağını gösterir.

using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
   array<Char>^chars = {'a','b','c',L'\u0300',L'\ua0a0'};
   array<Byte>^bytes;
   Encoder^ utf7Encoder = Encoding::UTF7->GetEncoder();
   int byteCount = utf7Encoder->GetByteCount( chars, 2, 3, true );
   bytes = gcnew array<Byte>(byteCount);
   int bytesEncodedCount = utf7Encoder->GetBytes( chars, 2, 3, bytes, 0, true );
   Console::WriteLine( "{0} bytes used to encode characters.", bytesEncodedCount );
   Console::Write( "Encoded bytes: " );
   IEnumerator^ myEnum = bytes->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Byte b = safe_cast<Byte>(myEnum->Current);
      Console::Write( "[{0}]", b );
   }

   Console::WriteLine();
}
using System;
using System.Text;

class UTF7EncodingExample {
    public static void Main() {
        Char[] chars = new Char[] {'a', 'b', 'c', '\u0300', '\ua0a0'};
        Byte[] bytes;

        Encoder utf7Encoder = Encoding.UTF7.GetEncoder();

        int byteCount = utf7Encoder.GetByteCount(chars, 2, 3, true);
        bytes = new Byte[byteCount];
        int bytesEncodedCount = utf7Encoder.GetBytes(chars, 2, 3, bytes, 0, true);

        Console.WriteLine(
            "{0} bytes used to encode characters.", bytesEncodedCount
        );

        Console.Write("Encoded bytes: ");
        foreach (Byte b in bytes) {
            Console.Write("[{0}]", b);
        }
        Console.WriteLine();
    }
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings

Class UTF7EncodingExample
    
    Public Shared Sub Main()
        'Characters:
        ' ChrW(97) = a
        ' ChrW(98) = b
        ' ChrW(99) = c
        ' ChrW(768) = `
        ' ChrW(41120) = valid unicode code point, but not a character
        Dim chars() As Char = {ChrW(97), ChrW(98), ChrW(99), ChrW(768), ChrW(41120)}
        Dim bytes() As Byte
        
        Dim utf7Encoder As Encoder = Encoding.UTF7.GetEncoder()
        
        Dim byteCount As Integer = utf7Encoder.GetByteCount(chars, 2, 3, True)
        bytes = New Byte(byteCount - 1) {}
        Dim bytesEncodedCount As Integer = utf7Encoder.GetBytes(chars, 2, 3, bytes, 0, True)
        
        Console.WriteLine("{0} bytes used to encode characters.", bytesEncodedCount)
        
        Console.Write("Encoded bytes: ")
        Dim b As Byte
        For Each b In  bytes
            Console.Write("[{0}]", b)
        Next b
        Console.WriteLine()
    End Sub
End Class

Açıklamalar

yöntemi, Decoder.GetChars baytların sıralı bloklarını yöntemine benzer şekilde sıralı karakter bloklarına GetChars dönüştürür. Ancak, bloklara yayılan bayt dizilerinin kodunu doğru bir şekilde çözebilmesi için çağrılar Decoder arasında durum bilgilerini korur. ayrıca Decoder veri bloklarının sonundaki sondaki baytları korur ve sonraki kod çözme işleminde sondaki baytları kullanır. Bu nedenle ve GetDecoderGetEncoder ağ iletimi ve dosya işlemleri için yararlıdır çünkü bu işlemler genellikle tam bir veri akışı yerine veri bloklarıyla ilgilenir.

Şunlara uygulanır

Ayrıca bkz.