Decoder クラス
エンコードされたバイトのブロックを Unicode 文字のブロックに変換します。
この型のすべてのメンバの一覧については、Decoder メンバ を参照してください。
System.Object
System.Text.Decoder
<Serializable>
MustInherit Public Class Decoder
[C#]
[Serializable]
public abstract class Decoder
[C++]
[Serializable]
public __gc __abstract class Decoder
[JScript]
public
Serializable
abstract class Decoder
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
これは抽象クラスです。派生クラスでこのクラスのメソッドをすべて実装し、オーバーライドする必要があります。
このクラスの実装は、 GetChars メソッドを連続して呼び出すことによって、エンコードされたバイトのブロックを Unicode 文字のブロックに変換します。このクラスは、後続の GetChars の呼び出しの間のステータス情報を維持し、隣接するブロックにまたがるバイトのシーケンスをデコードできるようにします。たとえば、 GetChars を使用すると、ストリームなど、特定の転送先を持たないバイト シーケンスをデコードできます。
GetCharCount メソッドは、指定したバイトのブロックをデコードすることによって生成された文字数を計算します。
System.Text.Encoding クラスから派生したクラスの GetDecoder メソッドを使用すると、 Decoder クラスのインスタンスを取得できます。
使用例
[Visual Basic, C#, C++] Decoder を使用して、2 つの異なるバイト配列を 1 つの文字配列に変換するコード例を次に示します。文字のバイトのいずれかが配列にまたがっています。これは、ストリームを読み取るときの System.IO.StreamReader の内部処理と似ています。
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, e3). 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, &HE3}
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+" + Convert.ToUInt16(c).ToString() + " ")
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, e3). 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, 0xe3 };
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+" + ((ushort)c).ToString() + " ");
}
}
[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, e3). 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, 0xe3 };
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);
for( UInt16 index(0); index < chars->Length; ++index ) {
Console::Write( String::Concat( S"U+", static_cast<UInt16>(chars[index]).ToString(), S" " ) );
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Text
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: Mscorlib (Mscorlib.dll 内)