クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System.Text
Decoder クラス
すべて縮小/すべて展開 すべて縮小
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
Decoder クラス
エンコード済みバイト シーケンスを文字のセットに変換します。

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

Visual Basic (宣言)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public MustInherit Class Decoder
Visual Basic (使用法)
Dim instance As Decoder
C#
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public abstract class Decoder
C++
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class Decoder abstract
J#
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public abstract class Decoder
JScript
SerializableAttribute 
ComVisibleAttribute(true) 
public abstract class Decoder
XAML
適用できません。

エンコーディングは、文字のセットをバイト シーケンスに変換するプロセスです。デコードはその逆になります。エンコードされたバイト シーケンスを文字のセットに変換するプロセスです。

Decoder では、複数のブロックにまたがるバイト シーケンスを正確にデコードできるように、GetChars への連続する呼び出し間でステータス情報を維持します。また、Decoder は、データ ブロックの末尾で後続バイトを保持し、その後続バイトを次のデコード操作に使用します。したがって、GetDecoderGetEncoder は、ネットワーク伝送やファイル操作に役立ちます。これは、ネットワーク伝送やファイル操作では、完全なデータ ストリームではなくデータのブロックを処理することが多いためです。

GetCharCount メソッドは、バイト シーケンスをデコードした結果生成される文字数を判断し、GetChars メソッドは、実際にデコードを実行します。

このクラスの実装のインスタンスを取得するには、Encoding 実装の GetDecoder メソッドを使用します。

バージョンの考慮事項

Decoder オブジェクトまたは Encoder オブジェクトは、変換演算の実行時にシリアル化できます。オブジェクトが .NET Framework の同じバージョンで逆シリアル化された場合、オブジェクトの状態は保持されますが、別のバージョンで逆シリアル化された場合には、オブジェクトの状態は失われます。

継承元へのメモ : このクラスから継承する場合は、すべてのメンバをオーバーライドする必要があります。

Decoder を使用して、2 つの異なるバイト配列を 1 つの文字配列に変換する例を次に示します。文字のバイトのいずれかが配列にまたがっています。これは、ストリームを読み取るときの System.IO.StreamReader の内部処理と似ています。

Visual Basic
Imports System
Imports System.Text

Public Class dec
    
    Public Shared Sub Main()
        ' These bytes in UTF-8 correspond to 3 different Unicode
        ' characters: space (U+0020), # (U+0023), and the biohazard
        ' symbol (U+2623).  Note the biohazard symbol requires 3 bytes
        ' in UTF-8 (hexadecimal e2, 98, a3).  Decoders store state across
        ' multiple calls to GetChars, handling the case when one char
        ' is in multiple byte arrays.
        Dim bytes1 As Byte() =  {&H20, &H23, &HE2}
        Dim bytes2 As Byte() =  {&H98, &HA3}
        Dim chars(3) As Char
        
        Dim d As Decoder = Encoding.UTF8.GetDecoder()
        Dim charLen As Integer = d.GetChars(bytes1, 0, bytes1.Length, chars, 0)
        ' The value of charLen should be 2 now.
        charLen += d.GetChars(bytes2, 0, bytes2.Length, chars, charLen)
        Dim c As Char
        For Each c In  chars
            Console.Write("U+{0:X4}  ", Convert.ToUInt16(c) )
        Next c
    End Sub
End Class
C#
using System;
using System.Text;
public class dec
{
    public static void Main()
    {
        // These bytes in UTF-8 correspond to 3 different Unicode
        // characters: space (U+0020), # (U+0023), and the biohazard
        // symbol (U+2623).  Note the biohazard symbol requires 3 bytes
        // in UTF-8 (hexadecimal e2, 98, a3).  Decoders store state across
        // multiple calls to GetChars, handling the case when one char
        // is in multiple byte arrays.
        byte[] bytes1 = { 0x20, 0x23, 0xe2 };
        byte[] bytes2 = { 0x98, 0xa3 };
        char[] chars = new char[3];

        Decoder d = Encoding.UTF8.GetDecoder();
        int charLen = d.GetChars(bytes1, 0, bytes1.Length, chars, 0);
        // The value of charLen should be 2 now.
        charLen += d.GetChars(bytes2, 0, bytes2.Length, chars, charLen);
        foreach(char c in chars)
            Console.Write("U+{0:X4}  ", (ushort)c);
    }
}
C++
using namespace System;
using namespace System::Text;
int main()
{
   
   // These bytes in UTF-8 correspond to 3 different Unicode
   // characters: space (U+0020), # (U+0023), and the biohazard
   // symbol (U+2623).  Note the biohazard symbol requires 3 bytes
   // in UTF-8 (hexadecimal e2, 98, a3).  Decoders store state across
   // multiple calls to GetChars, handling the case when one char
   // is in multiple byte arrays.
   array<Byte>^bytes1 = {0x20,0x23,0xe2};
   array<Byte>^bytes2 = {0x98,0xa3};
   array<Char>^chars = gcnew array<Char>(3);
   Decoder^ d = Encoding::UTF8->GetDecoder();
   int charLen = d->GetChars( bytes1, 0, bytes1->Length, chars, 0 );
   
   // The value of charLen should be 2 now.
   charLen += d->GetChars( bytes2, 0, bytes2->Length, chars, charLen );
   for ( UInt16 index(0); index < chars->Length; ++index )
   {
      Console::Write( "U+{0:X4}  ", static_cast<UInt16>(chars[ index ]) );

   }
}
J#
import System.*;
import System.Text.*;

public class Dec
{
    public static void main(String[] args)
    {
        // These bytes in UTF-8 correspond to 3 different Unicode
        // characters: space (U+0020), # (U+0023), and the biohazard
        // symbol (U+2623).  Note the biohazard symbol requires 3 bytes
        // in UTF-8 (hexadecimal e2, 98, a3).  Decoders store state across
        // multiple calls to GetChars, handling the case when one char
        // is in multiple byte arrays.
        ubyte bytes1[] =  { 0x20, 0x23, 0xE2 };
        ubyte bytes2[] =  { 0x98, 0xA3 };
        char chars[] = new char[3];
        
        Decoder d = Encoding.get_UTF8().GetDecoder();
        int charLen = d.GetChars(bytes1, 0, bytes1.length, chars, 0);
        
        // The value of charLen should be 2 now.
        charLen += d.GetChars(bytes2, 0, bytes2.length, chars, charLen);

        for (int iCtr = 0; iCtr < chars.length; iCtr++) {
            char c = chars[iCtr];
            Console.Write("U+{0}  ",((Int16)c).ToString("X4"));
        }
    } //main
} //Dec
System.Object
  System.Text.Decoder
この型の public static (Visual Basicでは共有) メンバはすべて,スレッド セーフです。インスタンス メンバの場合は,スレッド セーフであるとは限りません。

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

.NET Compact Framework

サポート対象 : 2.0,1.0

XNA Framework

サポート対象 : 1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2010 Microsoft Corporation. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker