UTF32Encoding クラス

定義

Unicode 文字の UTF-32 エンコーディングを表します。

public ref class UTF32Encoding sealed : System::Text::Encoding
public sealed class UTF32Encoding : System.Text.Encoding
[System.Serializable]
public sealed class UTF32Encoding : System.Text.Encoding
type UTF32Encoding = class
    inherit Encoding
[<System.Serializable>]
type UTF32Encoding = class
    inherit Encoding
Public NotInheritable Class UTF32Encoding
Inherits Encoding
継承
UTF32Encoding
属性

次の例は、エラー検出が有効になっているオブジェクトと、エラー検出が有効になっていないオブジェクトの UTF32Encoding 動作を示しています。 最後の 4 バイトが無効なサロゲート ペアを表すバイト配列を作成します。上位サロゲート U+D8FF の後に U+01FF が続き、下位サロゲート (0xDC00 ~ 0xDFFF) の範囲外です。 エラー検出を行わない場合、UTF32 デコーダーは置換フォールバックを使用して無効なサロゲート ペアを REPLACEMENT CHARACTER (U+FFFD) に置き換えます。

using namespace System;
using namespace System::Text;
void PrintDecodedString( array<Byte>^bytes, Encoding^ enc );
int main()
{
   
   // Create an instance of UTF32Encoding using little-endian byte order.
   // This will be used for encoding.
   UTF32Encoding^ u32LE = gcnew UTF32Encoding( false,true );
   
   // Create two instances of UTF32Encoding using big-endian byte order: one with error detection and one without.
   // These will be used for decoding.
   UTF32Encoding^ u32withED = gcnew UTF32Encoding( true,true,true );
   UTF32Encoding^ u32noED = gcnew UTF32Encoding( true,true,false );
   
   // Create byte arrays from the same string containing the following characters:
   //    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)
   String^ myStr = L"za\u0306\u01FD\u03B2\xD8FF\xDCFF";
   
   // Encode the string using little-endian byte order.
   array<Byte>^myBytes = gcnew array<Byte>(u32LE->GetByteCount( myStr ));
   u32LE->GetBytes( myStr, 0, myStr->Length, myBytes, 0 );
   
   // Decode the byte array with error detection.
   Console::WriteLine( "Decoding with error detection:" );
   PrintDecodedString( myBytes, u32withED );
   
   // Decode the byte array without error detection.
   Console::WriteLine( "Decoding without error detection:" );
   PrintDecodedString( myBytes, u32noED );
}


// Decode the bytes and display the string.
void PrintDecodedString( array<Byte>^bytes, Encoding^ enc )
{
   try
   {
      Console::WriteLine( "   Decoded string: {0}", enc->GetString( bytes, 0, bytes->Length ) );
   }
   catch ( System::ArgumentException^ e ) 
   {
      Console::WriteLine( e );
   }

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

public class Example
{
   public static void Main()
   {
     // Create a UTF32Encoding object with error detection enabled.
      var encExc = new UTF32Encoding(! BitConverter.IsLittleEndian, true, true);
      // Create a UTF32Encoding object with error detection disabled.
      var encRepl = new UTF32Encoding(! BitConverter.IsLittleEndian, true, false);

      // Create a byte arrays from a string, and add an invalid surrogate pair, as follows.
      //    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)
      //    a high-surrogate value (U+D8FF)
      //    an invalid low surrogate (U+01FF)
      String s = "za\u0306\u01FD\u03B2";

      // Encode the string using little-endian byte order.
      int index = encExc.GetByteCount(s);
      Byte[] bytes = new Byte[index + 4];
      encExc.GetBytes(s, 0, s.Length, bytes, 0);
      bytes[index] = 0xFF;
      bytes[index + 1] = 0xD8;
      bytes[index + 2] = 0xFF;
      bytes[index + 3] = 0x01;

      // Decode the byte array with error detection.
      Console.WriteLine("Decoding with error detection:");
      PrintDecodedString(bytes, encExc);

      // Decode the byte array without error detection.
      Console.WriteLine("Decoding without error detection:");
      PrintDecodedString(bytes, encRepl);
   }

   // Decode the bytes and display the string.
   public static void PrintDecodedString(Byte[] bytes, Encoding enc)
   {
      try {
         Console.WriteLine("   Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length));
      }
      catch (DecoderFallbackException e) {
         Console.WriteLine(e.ToString());
      }
      Console.WriteLine();
   }
}
// The example displays the following output:
//    Decoding with error detection:
//    System.Text.DecoderFallbackException: Unable to translate bytes [FF][D8][FF][01] at index
//    20 from specified code page to Unicode.
//       at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
//       at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index
//    )
//       at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
//       at System.Text.UTF32Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDeco
//    der)
//       at System.Text.UTF32Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
//       at Example.PrintDecodedString(Byte[] bytes, Encoding enc)
//
//    Decoding without error detection:
//       Decoded string: zăǽβ�
Imports System.Text

Public Module Example
   Public Sub Main()
      ' Create a UTF32Encoding object with error detection enabled.
      Dim encExc As New UTF32Encoding(Not BitConverter.IsLittleEndian, True, True)
      ' Create a UTF32Encoding object with error detection disabled.
      Dim encRepl As New UTF32Encoding(Not BitConverter.IsLittleEndian, True, False)

      ' Create a byte arrays from a string, and add an invalid surrogate pair, as follows.
      '    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)
      '    a high-surrogate value (U+D8FF)
      '    an invalid low surrogate (U+01FF)
      Dim s As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2)

      ' Encode the string using little-endian byte order.
      Dim index As Integer = encExc.GetBytecount(s)
      Dim bytes(index + 3) As Byte
      encExc.GetBytes(s, 0, s.Length, bytes, 0)
      bytes(index) = &hFF
      bytes(index + 1) = &hD8
      bytes(index + 2) = &hFF
      bytes(index + 3) = &h01

      ' Decode the byte array with error detection.
      Console.WriteLine("Decoding with error detection:")
      PrintDecodedString(bytes, encExc)

      ' Decode the byte array without error detection.
      Console.WriteLine("Decoding without error detection:")
      PrintDecodedString(bytes, encRepl)
   End Sub

   ' Decode the bytes and display the string.
   Public Sub PrintDecodedString(bytes() As Byte, enc As Encoding)
      Try
         Console.WriteLine("   Decoded string: {0}", enc.GetString(bytes, 0, bytes.Length))
      Catch e As DecoderFallbackException
         Console.WriteLine(e.ToString())
      End Try
      Console.WriteLine()
   End Sub
End Module
' The example displays the following output:
'    Decoding with error detection:
'    System.Text.DecoderFallbackException: Unable to translate bytes [FF][D8][FF][01] at index
'    20 from specified code page to Unicode.
'       at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
'       at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index
'    )
'       at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
'       at System.Text.UTF32Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDeco
'    der)
'       at System.Text.UTF32Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
'       at Example.PrintDecodedString(Byte[] bytes, Encoding enc)
'
'    Decoding without error detection:
'       Decoded string: zăǽβ�

次の例では、 オブジェクトを使用して Unicode 文字の文字列をバイト配列に UTF32Encoding エンコードします。 その後、バイト配列が文字列にデコードされ、データの損失がないことを示します。

using System;
using System.Text;

public class Example
{
    public static void Main()
    {
        // The encoding.
        var enc = new UTF32Encoding();
        
        // Create a string.
        String s = "This string contains two characters " +
                   "with codes outside the ASCII code range: " +
                   "Pi (\u03A0) and Sigma (\u03A3).";
        Console.WriteLine("Original string:");
        Console.WriteLine("   {0}", s);
        
        // Encode the string.
        Byte[] encodedBytes = enc.GetBytes(s);
        Console.WriteLine();
        Console.WriteLine("Encoded bytes:");
        for (int ctr = 0; ctr < encodedBytes.Length; ctr++) {
            Console.Write("[{0:X2}]{1}", encodedBytes[ctr],
                                         (ctr + 1) % 4 == 0 ? " " : "" );
            if ((ctr + 1) % 16 == 0) Console.WriteLine();
        }
        Console.WriteLine();
        
        // Decode bytes back to string.
        // Notice Pi and Sigma characters are still present.
        String decodedString = enc.GetString(encodedBytes);
        Console.WriteLine();
        Console.WriteLine("Decoded string:");
        Console.WriteLine("   {0}", decodedString);
    }
}
// The example displays the following output:
//    Original string:
//       This string contains two characters with codes outside the ASCII code range:
//    Pi (π) and Sigma (Σ).
//
//    Encoded bytes:
//    [54][00][00][00] [68][00][00][00] [69][00][00][00] [73][00][00][00]
//    [20][00][00][00] [73][00][00][00] [74][00][00][00] [72][00][00][00]
//    [69][00][00][00] [6E][00][00][00] [67][00][00][00] [20][00][00][00]
//    [63][00][00][00] [6F][00][00][00] [6E][00][00][00] [74][00][00][00]
//    [61][00][00][00] [69][00][00][00] [6E][00][00][00] [73][00][00][00]
//    [20][00][00][00] [74][00][00][00] [77][00][00][00] [6F][00][00][00]
//    [20][00][00][00] [63][00][00][00] [68][00][00][00] [61][00][00][00]
//    [72][00][00][00] [61][00][00][00] [63][00][00][00] [74][00][00][00]
//    [65][00][00][00] [72][00][00][00] [73][00][00][00] [20][00][00][00]
//    [77][00][00][00] [69][00][00][00] [74][00][00][00] [68][00][00][00]
//    [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
//    [65][00][00][00] [73][00][00][00] [20][00][00][00] [6F][00][00][00]
//    [75][00][00][00] [74][00][00][00] [73][00][00][00] [69][00][00][00]
//    [64][00][00][00] [65][00][00][00] [20][00][00][00] [74][00][00][00]
//    [68][00][00][00] [65][00][00][00] [20][00][00][00] [41][00][00][00]
//    [53][00][00][00] [43][00][00][00] [49][00][00][00] [49][00][00][00]
//    [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
//    [65][00][00][00] [20][00][00][00] [72][00][00][00] [61][00][00][00]
//    [6E][00][00][00] [67][00][00][00] [65][00][00][00] [3A][00][00][00]
//    [20][00][00][00] [50][00][00][00] [69][00][00][00] [20][00][00][00]
//    [28][00][00][00] [A0][03][00][00] [29][00][00][00] [20][00][00][00]
//    [61][00][00][00] [6E][00][00][00] [64][00][00][00] [20][00][00][00]
//    [53][00][00][00] [69][00][00][00] [67][00][00][00] [6D][00][00][00]
//    [61][00][00][00] [20][00][00][00] [28][00][00][00] [A3][03][00][00]
//    [29][00][00][00] [2E][00][00][00]
//
//    Decoded string:
//       This string contains two characters with codes outside the ASCII code range:
//    Pi (π) and Sigma (Σ).
Imports System.Text

Class Example
    Public Shared Sub Main()
        ' The encoding.
        Dim enc As New UTF32Encoding()
        
        ' Create a string.
        Dim s As String =
            "This string contains two characters " &
            "with codes outside the ASCII code range: " &
            "Pi (" & ChrW(&h03A0) & ") and Sigma (" & ChrW(&h03A3) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine("   {0}", s)
        
        ' Encode the string.
        Dim encodedBytes As Byte() = enc.GetBytes(s)
        Console.WriteLine()
        Console.WriteLine("Encoded bytes:")
        For ctr As Integer = 0 To encodedBytes.Length - 1
            Console.Write("[{0:X2}]{1}", encodedBytes(ctr),
                                         If((ctr + 1) Mod 4 = 0, " ", "" ))
            If (ctr + 1) Mod 16 = 0 Then Console.WriteLine()
        Next
        Console.WriteLine()
        
        ' Decode bytes back to string.
        ' Notice Pi and Sigma characters are still present.
        Dim decodedString As String = enc.GetString(encodedBytes)
        Console.WriteLine()
        Console.WriteLine("Decoded string:")
        Console.WriteLine("   {0}", decodedString)
    End Sub
End Class
' The example displays the following output:
'    Original string:
'       This string contains two characters with codes outside the ASCII code range:
'    Pi (π) and Sigma (Σ).
'
'    Encoded bytes:
'    [54][00][00][00] [68][00][00][00] [69][00][00][00] [73][00][00][00]
'    [20][00][00][00] [73][00][00][00] [74][00][00][00] [72][00][00][00]
'    [69][00][00][00] [6E][00][00][00] [67][00][00][00] [20][00][00][00]
'    [63][00][00][00] [6F][00][00][00] [6E][00][00][00] [74][00][00][00]
'    [61][00][00][00] [69][00][00][00] [6E][00][00][00] [73][00][00][00]
'    [20][00][00][00] [74][00][00][00] [77][00][00][00] [6F][00][00][00]
'    [20][00][00][00] [63][00][00][00] [68][00][00][00] [61][00][00][00]
'    [72][00][00][00] [61][00][00][00] [63][00][00][00] [74][00][00][00]
'    [65][00][00][00] [72][00][00][00] [73][00][00][00] [20][00][00][00]
'    [77][00][00][00] [69][00][00][00] [74][00][00][00] [68][00][00][00]
'    [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
'    [65][00][00][00] [73][00][00][00] [20][00][00][00] [6F][00][00][00]
'    [75][00][00][00] [74][00][00][00] [73][00][00][00] [69][00][00][00]
'    [64][00][00][00] [65][00][00][00] [20][00][00][00] [74][00][00][00]
'    [68][00][00][00] [65][00][00][00] [20][00][00][00] [41][00][00][00]
'    [53][00][00][00] [43][00][00][00] [49][00][00][00] [49][00][00][00]
'    [20][00][00][00] [63][00][00][00] [6F][00][00][00] [64][00][00][00]
'    [65][00][00][00] [20][00][00][00] [72][00][00][00] [61][00][00][00]
'    [6E][00][00][00] [67][00][00][00] [65][00][00][00] [3A][00][00][00]
'    [20][00][00][00] [50][00][00][00] [69][00][00][00] [20][00][00][00]
'    [28][00][00][00] [A0][03][00][00] [29][00][00][00] [20][00][00][00]
'    [61][00][00][00] [6E][00][00][00] [64][00][00][00] [20][00][00][00]
'    [53][00][00][00] [69][00][00][00] [67][00][00][00] [6D][00][00][00]
'    [61][00][00][00] [20][00][00][00] [28][00][00][00] [A3][03][00][00]
'    [29][00][00][00] [2E][00][00][00]
'
'    Decoded string:
'       This string contains two characters with codes outside the ASCII code range:
'    Pi (π) and Sigma (Σ).

次の例では、前の文字列と同じ文字列を使用しますが、エンコードされたバイトをファイルに書き込み、バイト ストリームの前にバイトオーダー マーク (BOM) を付けます。 次に、オブジェクトを使用 StreamReader してテキスト ファイルとして、バイナリ ファイルとしてという 2 つの異なる方法でファイルを読み取ります。 予想通り、新しく読み取られた文字列には BOM は含まれます。

using System;
using System.IO;
using System.Text;

public class Example
{
    public static void Main()
    {
        // Create a UTF-32 encoding that supports a BOM.
        var enc = new UTF32Encoding();
        
        // A Unicode string with two characters outside an 8-bit code range.
        String s = "This Unicode string has 2 characters " +
                   "outside the ASCII range: \n" +
                   "Pi (\u03A0), and Sigma (\u03A3).";
        Console.WriteLine("Original string:");
        Console.WriteLine(s);
        Console.WriteLine();
        
        // Encode the string.
        Byte[] encodedBytes = enc.GetBytes(s);
        Console.WriteLine("The encoded string has {0} bytes.\n",
                          encodedBytes.Length);

        // Write the bytes to a file with a BOM.
        var fs = new FileStream(@".\UTF32Encoding.txt", FileMode.Create);
        Byte[] bom = enc.GetPreamble();
        fs.Write(bom, 0, bom.Length);
        fs.Write(encodedBytes, 0, encodedBytes.Length);
        Console.WriteLine("Wrote {0} bytes to the file.\n", fs.Length);
        fs.Close();

        // Open the file using StreamReader.
        var sr = new StreamReader(@".\UTF32Encoding.txt");
        String newString = sr.ReadToEnd();
        sr.Close();
        Console.WriteLine("String read using StreamReader:");
        Console.WriteLine(newString);
        Console.WriteLine();
        
        // Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(@".\Utf32Encoding.txt", FileMode.Open);
        Byte[] bytes = new Byte[fs.Length];
        fs.Read(bytes, 0, (int)fs.Length);
        fs.Close();

        String decodedString = enc.GetString(bytes);
        Console.WriteLine("Decoded bytes from binary file:");
        Console.WriteLine(decodedString);
    }
}
// The example displays the following output:
//    Original string:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    The encoded string has 340 bytes.
//
//    Wrote 344 bytes to the file.
//
//    String read using StreamReader:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    Decoded bytes from binary file:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
Imports System.IO
Imports System.Text

Class Example
    Public Shared Sub Main()
        ' Create a UTF-32 encoding that supports a BOM.
        Dim enc As New UTF32Encoding()
        
        ' A Unicode string with two characters outside an 8-bit code range.
        Dim s As String = _
            "This Unicode string has 2 characters outside the " &
            "ASCII range: " & vbCrLf &
            "Pi (" & ChrW(&h03A0) & "), and Sigma (" & ChrW(&h03A3) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(s)
        Console.WriteLine()
        
        ' Encode the string.
        Dim encodedBytes As Byte() = enc.GetBytes(s)
        Console.WriteLine("The encoded string has {0} bytes.",
                          encodedBytes.Length)
        Console.WriteLine()
        
        ' Write the bytes to a file with a BOM.
        Dim fs As New FileStream(".\UTF32Encoding.txt", FileMode.Create)
        Dim bom() As Byte = enc.GetPreamble()
        fs.Write(bom, 0, bom.Length)
        fs.Write(encodedBytes, 0, encodedBytes.Length)
        Console.WriteLine("Wrote {0} bytes to the file.", fs.Length)
        fs.Close()
        Console.WriteLine()
        
        ' Open the file using StreamReader.
        Dim sr As New StreamReader(".\UTF32Encoding.txt")
        Dim newString As String = sr.ReadToEnd()
        sr.Close()
        Console.WriteLine("String read using StreamReader:")
        Console.WriteLine(newString)
        Console.WriteLine()
        
        ' Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(".\Utf32Encoding.txt", FileMode.Open)
        Dim bytes(fs.Length - 1) As Byte
        fs.Read(bytes, 0, fs.Length)
        fs.Close()

        Dim decodedString As String = enc.GetString(bytes)
        Console.WriteLine("Decoded bytes from binary file:")
        Console.WriteLine(decodedString)
    End Sub
End Class
' The example displays the following output:
'    Original string:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    The encoded string has 344 bytes.
'
'    Wrote 348 bytes to the file.
'
'    String read using StreamReader:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    Decoded bytes from binary file:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).

注釈

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

Unicode 標準では、サポートされているすべてのスクリプトの各文字にコード ポイント (数値) が割り当てられます。 Unicode 変換形式 (UTF) は、そのコード ポイントをエンコードする方法です。 Unicode 標準では、次の UDF が使用されます。

  • UTF-8。各コード ポイントを 1 ~ 4 バイトのシーケンスとして表します。

  • UTF-16。各コード ポイントを 1 ~ 2 個の 16 ビット整数のシーケンスとして表します。

  • UTF-32。各コード ポイントを 32 ビット整数として表します。

でサポートされている System.TextUDF とその他のエンコードの詳細については、「 .NET での文字エンコード」を参照してください。

クラスは UTF32Encoding UTF-32 エンコードを表します。 エンコーダーでは、ビッグ エンディアンバイトオーダー (最上位バイト優先) またはリトルエンディアンバイトオーダー (最下位バイト優先) を使用できます。 たとえば、英大文字 A (コード ポイント U+0041) は、次のようにシリアル化されます (16 進数)。

  • ビッグ エンディアン バイト順: 00 00 00 41

  • リトル エンディアン バイト順: 41 00 00 00

一般に、ネイティブバイト順序を使用して Unicode 文字を格納する方が効率的です。 たとえば、Intel コンピューターなどのリトルエンディアンプラットフォームでは、リトルエンディアンのバイト順を使用することをお勧めします。 UTF32Encoding は、Windows コード ページ 12000 (リトル エンディアン バイト順) と 12001 (ビッグ エンディアン バイト順) に対応します。 メソッドを呼び出すことで、特定のアーキテクチャの "エンディアン" を BitConverter.IsLittleEndian 判断できます。

必要に応じて、 UTF32Encoding オブジェクトはバイト オーダー マーク (BOM) を提供します。これは、エンコード プロセスの結果のバイト シーケンスにプレフィックスを付けることができるバイト配列です。 プリアンブルにバイトオーダーマーク(BOM)が含まれている場合は、デコーダーがバイト配列のバイトオーダーと変換形式またはUTFを決定するのに役立ちます。

インスタンスが UTF32Encoding BOM を提供するように構成されている場合は、 メソッドを呼び出 GetPreamble して取得できます。それ以外の場合、メソッドは空の配列を返します。 オブジェクトが BOM サポート用に構成されている場合 UTF32Encoding でも、エンコードされたバイト ストリームの先頭に必要に応じて BOM を含める必要があることに注意してください。クラスの UTF32Encoding エンコード メソッドでは、この処理は自動的には行われません。

注意事項

エラー検出を有効にし、クラス インスタンスをより安全にするには、コンストラクターを呼び出し、そのthrowOnInvalidBytes引数を UTF32Encoding(Boolean, Boolean, Boolean) に設定することで、オブジェクトをインスタンス化UTF32Encodingするtrue必要があります。 エラー検出では、無効な一連の文字またはバイトを検出するメソッドが例外を ArgumentException スローします。 エラー検出がないと、例外はスローされず、無効なシーケンスは一般に無視されます。

バイト オーダー マーク (BOM) を提供するかどうか、ビッグ エンディアンエンコードとリトル エンディアン エンコードのどちらを使用するか、エラー検出を有効にするかどうかに応じて、さまざまな方法でオブジェクトをインスタンス化 UTF32Encoding できます。 次の表に、 オブジェクトを UTF32Encoding 返すコンストラクターとプロパティの Encoding 一覧を UnicodeEncoding 示します。

メンバー エンディアン BOM エラー検出
Encoding.UTF32 リトル エンディアン はい いいえ (置換フォールバック)
UTF32Encoding.UTF32Encoding() リトル エンディアン はい いいえ (置換フォールバック)
UTF32Encoding.UTF32Encoding(Boolean, Boolean) 構成可能 構成可能 いいえ (置換フォールバック)
UTF32Encoding.UTF32Encoding(Boolean, Boolean, Boolean) 構成可能 構成可能 構成可能

メソッドによって、 GetByteCount Unicode 文字のセットをエンコードするバイト数が決定され、 GetBytes メソッドは実際のエンコーディングを実行します。

同様に、 メソッドは GetCharCount バイトシーケンスをデコードする結果の文字数を決定し、 メソッドと GetCharsGetString メソッドは実際のデコードを実行します。

複数のブロックにまたがるデータをエンコードまたはデコードするときに状態情報を保存できるエンコーダーまたはデコーダー (100,000 文字のセグメントでエンコードされた 100 万文字の文字列など) の場合は、 プロパティと GetDecoder プロパティをそれぞれ使用GetEncoderします。

コンストラクター

UTF32Encoding()

UTF32Encoding クラスの新しいインスタンスを初期化します。

UTF32Encoding(Boolean, Boolean)

UTF32Encoding クラスの新しいインスタンスを初期化します。 パラメーターでは、ビッグ エンディアン バイト順を使用するかどうか、および GetPreamble() メソッドが Unicode バイト順マークを返すかどうかを指定します。

UTF32Encoding(Boolean, Boolean, Boolean)

UTF32Encoding クラスの新しいインスタンスを初期化します。 パラメーターでは、ビッグ エンディアン バイト順を使用するかどうか、Unicode バイト順マークを付加するかどうか、および無効なエンコーディングを検出したときに例外をスローするかどうかを指定します。

プロパティ

BodyName

派生クラスでオーバーライドされた場合、メール エージェントの Body タグと共に使用できる現在のエンコーディングの名前を取得します。

(継承元 Encoding)
CodePage

派生クラスでオーバーライドされた場合、現在の Encoding のコード ページ ID を取得します。

(継承元 Encoding)
DecoderFallback

現在の DecoderFallback オブジェクトの Encoding オブジェクトを取得または設定します。

(継承元 Encoding)
EncoderFallback

現在の EncoderFallback オブジェクトの Encoding オブジェクトを取得または設定します。

(継承元 Encoding)
EncodingName

派生クラスでオーバーライドされた場合、現在のエンコーディングについての記述を、ユーザーが判読できる形式で取得します。

(継承元 Encoding)
HeaderName

派生クラスでオーバーライドされた場合、メール エージェント ヘッダー タグと共に使用できる現在のエンコーディングの名前を取得します。

(継承元 Encoding)
IsBrowserDisplay

派生クラスでオーバーライドされた場合、ブラウザー クライアントが現在のエンコーディングを使用してコンテンツを表示できるかどうかを示す値を取得します。

(継承元 Encoding)
IsBrowserSave

派生クラスでオーバーライドされた場合、ブラウザー クライアントが現在のエンコーディングを使用してコンテンツを保存できるかどうかを示す値を取得します。

(継承元 Encoding)
IsMailNewsDisplay

派生クラスでオーバーライドされた場合、メール クライアントおよびニュース クライアントが現在のエンコーディングを使用してコンテンツを表示できるかどうかを示す値を取得します。

(継承元 Encoding)
IsMailNewsSave

派生クラスでオーバーライドされた場合、メール クライアントおよびニュース クライアントが現在のエンコーディングを使用してコンテンツを保存できるかどうかを示す値を取得します。

(継承元 Encoding)
IsReadOnly

派生クラスでオーバーライドされた場合、現在のエンコーディングが読み取り専用かどうかを示す値を取得します。

(継承元 Encoding)
IsSingleByte

派生クラスでオーバーライドされた場合、現在のエンコーディングが 1 バイトのコード ポイントを使用するかどうかを示す値を取得します。

(継承元 Encoding)
Preamble

このオブジェクトが UTF-32 形式でエンコードされた Unicode バイト順マークを提供するように構成されている場合は、そのようなマークを取得します。

Preamble

派生クラスでオーバーライドされた場合、使用するエンコードを指定するバイト シーケンスを含むスパンが返されます。

(継承元 Encoding)
WebName

派生クラスでオーバーライドされた場合、現在のエンコーディングの IANA (Internet Assigned Numbers Authority) に登録されている名前を取得します。

(継承元 Encoding)
WindowsCodePage

派生クラスでオーバーライドされた場合、現在のエンコーディングに最も厳密に対応する Windows オペレーティング システムのコード ページを取得します。

(継承元 Encoding)

メソッド

Clone()

派生クラスでオーバーライドされた場合、現在の Encoding オブジェクトの簡易コピーを作成します。

(継承元 Encoding)
Equals(Object)

指定した Object が、現在の UTF32Encoding オブジェクトと等しいかどうかを判断します。

GetByteCount(Char*, Int32)

指定した文字ポインターで始まる文字のセットをエンコードすることによって生成されるバイト数を計算します。

GetByteCount(Char[])

派生クラスでオーバーライドされた場合、指定した文字配列に格納されているすべての文字をエンコードすることによって生成されるバイト数を計算します。

(継承元 Encoding)
GetByteCount(Char[], Int32, Int32)

指定した文字配列から文字のセットをエンコードすることによって生成されるバイト数を計算します。

GetByteCount(ReadOnlySpan<Char>)

派生クラスでオーバーライドされた場合、指定した文字スパンに格納されている文字をエンコードすることによって生成されるバイト数を計算します。

(継承元 Encoding)
GetByteCount(String)

指定した String 内の文字をエンコードすることによって生成されるバイト数を計算します。

GetByteCount(String, Int32, Int32)

派生クラスでオーバーライドされた場合、指定した文字列の文字のセットをエンコードすることによって生成されるバイト数を計算します。

(継承元 Encoding)
GetBytes(Char*, Int32, Byte*, Int32)

指定した文字ポインターで始まる文字のセットを、指定したバイト ポインターを開始位置として格納されるバイト シーケンスにエンコードします。

GetBytes(Char[])

派生クラスでオーバーライドされた場合、指定した文字配列に格納されているすべての文字をバイト シーケンスにエンコードします。

(継承元 Encoding)
GetBytes(Char[], Int32, Int32)

派生クラスでオーバーライドされた場合、指定した文字配列に格納されている文字のセットをバイト シーケンスにエンコードします。

(継承元 Encoding)
GetBytes(Char[], Int32, Int32, Byte[], Int32)

指定した文字配列に格納されている文字のセットを指定したバイト配列にエンコードします。

GetBytes(ReadOnlySpan<Char>, Span<Byte>)

派生クラスでオーバーライドされた場合、指定した読み取り専用スパンに格納されている文字のセットをバイトのスパンにエンコードします。

(継承元 Encoding)
GetBytes(String)

派生クラスでオーバーライドされた場合、指定した文字列に含まれるすべての文字をバイト シーケンスにエンコードします。

(継承元 Encoding)
GetBytes(String, Int32, Int32)

派生クラスでオーバーライドされた場合、指定した文字列内の count で指定した数の文字を、指定した index からバイト配列にエンコードします。

(継承元 Encoding)
GetBytes(String, Int32, Int32, Byte[], Int32)

指定した String の文字セットを、指定したバイト配列にエンコードします。

GetCharCount(Byte*, Int32)

指定したバイト ポインターで始まるバイト シーケンスをデコードすることによって生成される文字数を計算します。

GetCharCount(Byte[])

派生クラスでオーバーライドされた場合、指定したバイト配列に格納されているすべてのバイトをデコードすることによって生成される文字数を計算します。

(継承元 Encoding)
GetCharCount(Byte[], Int32, Int32)

指定したバイト配列からバイト シーケンスをデコードすることによって生成される文字数を計算します。

GetCharCount(ReadOnlySpan<Byte>)

派生クラスでオーバーライドされた場合、指定した読み取り専用バイト スパンをデコードすることによって生成される文字数を計算します。

(継承元 Encoding)
GetChars(Byte*, Int32, Char*, Int32)

指定したバイト ポインターで始まるバイト シーケンスを、指定した文字ポインターを開始位置として格納される文字のセットにデコードします。

GetChars(Byte[])

派生クラスでオーバーライドされた場合、指定したバイト配列に格納されているすべてのバイトを文字のセットにデコードします。

(継承元 Encoding)
GetChars(Byte[], Int32, Int32)

派生クラスでオーバーライドされた場合、指定したバイト配列に格納されているバイト シーケンスを文字のセットにデコードします。

(継承元 Encoding)
GetChars(Byte[], Int32, Int32, Char[], Int32)

指定したバイト配列に格納されているバイト シーケンスを指定した文字配列にデコードします。

GetChars(ReadOnlySpan<Byte>, Span<Char>)

派生クラスでオーバーライドされた場合、指定した読み取り専用バイト スパンに格納されているすべてのバイトを、文字スパンにデコードします。

(継承元 Encoding)
GetDecoder()

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

GetEncoder()

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

GetHashCode()

現在のインスタンスのハッシュ コードを返します。

GetMaxByteCount(Int32)

指定した文字数をエンコードすることによって生成される最大バイト数を計算します。

GetMaxCharCount(Int32)

指定したバイト数をデコードすることによって生成される最大文字数を計算します。

GetPreamble()

UTF32Encoding オブジェクトが UTF-32 形式でエンコードされた Unicode バイト順マークを提供するように構成されている場合、そのようなマークが返されます。

GetString(Byte*, Int32)

派生クラスでオーバーライドされた場合、指定したアドレスで始まる指定したバイト数を文字列にデコードします。

(継承元 Encoding)
GetString(Byte[])

派生クラスでオーバーライドされた場合、指定したバイト配列に格納されているすべてのバイトを文字列にデコードします。

(継承元 Encoding)
GetString(Byte[], Int32, Int32)

バイト配列に格納されているある範囲のバイトを文字列にデコードします。

GetString(ReadOnlySpan<Byte>)

派生クラスでオーバーライドされた場合、指定したバイト スパンに格納されているすべてのバイトを文字列にデコードします。

(継承元 Encoding)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsAlwaysNormalized()

現在のエンコーディングが、既定の正規形を使用して常に正規化されるかどうかを示す値。

(継承元 Encoding)
IsAlwaysNormalized(NormalizationForm)

派生クラスでオーバーライドされた場合、現在のエンコーディングが、指定した正規形を使用して常に正規化されるかどうかを示す値を取得します。

(継承元 Encoding)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
TryGetBytes(ReadOnlySpan<Char>, Span<Byte>, Int32)

宛先が十分な大きさである場合は、指定した読み取り専用スパンから一連の文字をバイトスパンにエンコードします。

(継承元 Encoding)
TryGetChars(ReadOnlySpan<Byte>, Span<Char>, Int32)

宛先が十分に大きい場合は、指定した読み取り専用スパンからバイトセットを文字のスパンにデコードします。

(継承元 Encoding)

拡張メソッド

GetBytes(Encoding, ReadOnlySequence<Char>)

指定された Encoding を使用して、指定された ReadOnlySequence<T>Byte 配列にエンコードします。

GetBytes(Encoding, ReadOnlySequence<Char>, IBufferWriter<Byte>)

指定された Encoding を使用して指定された ReadOnlySequence<T>byte にデコードし、結果を writer に書き込みます。

GetBytes(Encoding, ReadOnlySequence<Char>, Span<Byte>)

指定された Encoding を使用して指定された ReadOnlySequence<T>byte にエンコードし、結果を bytes に出力します。

GetBytes(Encoding, ReadOnlySpan<Char>, IBufferWriter<Byte>)

指定された Encoding を使用して指定された ReadOnlySpan<T>byte にエンコードし、結果を writer に書き込みます。

GetChars(Encoding, ReadOnlySequence<Byte>, IBufferWriter<Char>)

指定された Encoding を使用して指定された ReadOnlySequence<T>char にデコードし、結果を writer に書き込みます。

GetChars(Encoding, ReadOnlySequence<Byte>, Span<Char>)

指定された Encoding を使用して指定された ReadOnlySequence<T>char にデコードし、結果を chars に出力します。

GetChars(Encoding, ReadOnlySpan<Byte>, IBufferWriter<Char>)

指定された Encoding を使用して指定された ReadOnlySpan<T>char にデコードし、結果を writer に書き込みます。

GetString(Encoding, ReadOnlySequence<Byte>)

指定された Encoding を使用して、指定された ReadOnlySequence<T>String にデコードします。

適用対象

こちらもご覧ください