次の方法で共有


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 が続きます。U+01FF は、下位サロゲートの範囲外です (0xDC00 ~ 0xDFFF)。 エラー検出を行わない場合、UTF32 デコーダーは代替フォールバックを使用して無効なサロゲート ペアを REPLACEMENT CHARACTER (U+FFFD) に置き換えます。

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ăǽβ�

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

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.Textでサポートされている UDF とその他のエンコードの詳細については、「.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 メソッドを呼び出して取得できます。それ以外の場合、メソッドは空の配列を返します。 UTF32Encoding オブジェクトが BOM サポート用に構成されている場合でも、必要に応じてエンコードされたバイト ストリームの先頭に BOM を含める必要があります。UTF32Encoding クラスのエンコード メソッドでは、この処理は自動的には行われません。

注意事項

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

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

メンバー エンディアン BOM エラー検出
Encoding.UTF32 リトル エンディアン はい いいえ (代替フォールバック)
UTF32Encoding.UTF32Encoding() リトル エンディアン はい いいえ (代替フォールバック)
UTF32Encoding.UTF32Encoding(Boolean, Boolean) Configurable Configurable いいえ (代替フォールバック)
UTF32Encoding.UTF32Encoding(Boolean, Boolean, Boolean) Configurable Configurable Configurable

GetByteCountメソッドは、Unicode 文字のセットをエンコードする結果のバイト数を決定し、GetBytes メソッドは実際のエンコードを実行します。

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

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

コンストラクター

名前 説明
UTF32Encoding()

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

UTF32Encoding(Boolean, Boolean, Boolean)

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

UTF32Encoding(Boolean, Boolean)

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

プロパティ

名前 説明
BodyName

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

(継承元 Encoding)
CodePage

派生クラスでオーバーライドされると、現在の Encodingのコード ページ識別子を取得します。

(継承元 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 バイトオーダー マークを取得します (このオブジェクトが UTF-32 形式を指定するように構成されている場合)。

Preamble

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

(継承元 Encoding)
WebName

派生クラスでオーバーライドされると、現在のエンコードのインターネット割り当て番号機関 (IANA) に登録されている名前を取得します。

(継承元 Encoding)
WindowsCodePage

派生クラスでオーバーライドされると、現在のエンコードに最も近い Windows オペレーティング システム コード ページを取得します。

(継承元 Encoding)

メソッド

名前 説明
Clone()

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

(継承元 Encoding)
Equals(Object)

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

GetByteCount(Char[], Int32, Int32)

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

GetByteCount(Char[])

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

(継承元 Encoding)
GetByteCount(Char*, Int32)

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

GetByteCount(ReadOnlySpan<Char>)

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

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

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

(継承元 Encoding)
GetByteCount(String)

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

GetBytes(Char[], Int32, Int32, Byte[], Int32)

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

GetBytes(Char[], Int32, Int32)

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

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

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

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

指定した文字ポインターから始まる一連の文字を、指定したバイト ポインターから始めて格納されるバイトシーケンスにエンコードします。

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

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

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

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

GetBytes(String, Int32, Int32)

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

(継承元 Encoding)
GetBytes(String)

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

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

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

GetCharCount(Byte[])

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

(継承元 Encoding)
GetCharCount(Byte*, Int32)

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

GetCharCount(ReadOnlySpan<Byte>)

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

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

指定したバイト配列から指定した文字配列にバイト シーケンスをデコードします。

GetChars(Byte[], Int32, Int32)

派生クラスでオーバーライドされると、指定したバイト配列のバイト シーケンスを一連の文字にデコードします。

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

派生クラスでオーバーライドされると、指定したバイト配列内のすべてのバイトを一連の文字にデコードします。

(継承元 Encoding)
GetChars(Byte*, 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, Int32)

バイト配列から文字列にバイト範囲をデコードします。

GetString(Byte[])

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

(継承元 Encoding)
GetString(Byte*, Int32)

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

(継承元 Encoding)
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>, IBufferWriter<Byte>)

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

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

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

GetBytes(Encoding, ReadOnlySequence<Char>)

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

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

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

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

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

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

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

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

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

GetString(Encoding, ReadOnlySequence<Byte>)

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

適用対象

こちらもご覧ください