UnicodeEncoding.GetEncoder メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > UnicodeEncoding.GetEncoder メソッドの意味・解説 

UnicodeEncoding.GetEncoder メソッド

Unicode 文字シーケンスUTF-32エンコードされたバイト シーケンス変換するエンコーダ取得します

名前空間: System.Text
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(False)> _
Public Overrides Function
 GetEncoder As Encoder
Dim instance As UnicodeEncoding
Dim returnValue As Encoder

returnValue = instance.GetEncoder
[ComVisibleAttribute(false)] 
public override Encoder GetEncoder ()
[ComVisibleAttribute(false)] 
public:
virtual Encoder^ GetEncoder () override
/** @attribute ComVisibleAttribute(false) */ 
public Encoder GetEncoder ()
ComVisibleAttribute(false) 
public override function GetEncoder () : Encoder

戻り値
Unicode 文字シーケンスUTF-32エンコードされたバイト シーケンス変換する Encoder オブジェクト

解説解説

Encoder.GetBytes メソッドは、このクラスの GetBytes メソッド同様の方法で、連続する文字ブロック連続するバイト ブロック変換します。ただし、Encoder オブジェクトでは、複数ブロックにまたがる文字シーケンス正確にエンコードできるように、呼び出し間でステータス情報維持します。また、Encoder オブジェクトは、データ ブロック末尾後続文字保持しその後文字次のエンコード操作使用します。たとえば、データ ブロック上位サロゲート終了し対応する下位サロゲート次のデータ ブロック含まれる場合あります。したがって、GetDecoder と GetEncoder は、ネットワーク伝送ファイル操作役立ちます。これは、ネットワーク伝送ファイル操作では、完全なデータ ストリームではなくデータブロック処理することが多いためです。

このインスタンスエラー検出有効になっている場合、つまり、コンストラクタthrowOnInvalidBytes パラメータtrue設定され場合は、このメソッドによって返される Encoder オブジェクト内でもエラー検出が有効です。エラー検出有効にしている場合無効なシーケンス検出されると、エンコーダの状態が定義されていないため、処理は中止されます。

使用例使用例

次のコード例は、エンコーダデコーダ使用して文字列バイト配列エンコードし、そのバイト文字配列デコードます。

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??

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UnicodeEncoding クラス
UnicodeEncoding メンバ
System.Text 名前空間
Encoder クラス
GetBytes
GetByteCount
GetDecoder


このページでは「.NET Framework クラス ライブラリ リファレンス」からUnicodeEncoding.GetEncoder メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からUnicodeEncoding.GetEncoder メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からUnicodeEncoding.GetEncoder メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

UnicodeEncoding.GetEncoder メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



UnicodeEncoding.GetEncoder メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS