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

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

UTF32Encoding.GetPreamble メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

このインスタンスのコンストラクタでバイト順マークを付加するよう指定した場合に、UTF-32 形式でエンコードされた Unicode バイト順マークを返します。

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

解説解説

プリアンブルがエンコード済みストリームの前に付加されていると、使用されているエンコーディング形式をデコーダが識別するのに役立ちます。

エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。

UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。

通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。

バイト順とバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。

注意に関するメモ注意

エンコード済みバイトを正しくデコードするには、エンコード済みバイトの前にプリアンブルを付加します。

使用例使用例

次のコード例は、さまざまな UTF32Encoding インスタンスのバイト順マークを取得して表示します。

Imports System
Imports System.Text

Public Class SamplesUTF32Encoding   

   Public Shared Sub Main()

      ' Create instances of UTF32Encoding, with the byte order mark
 and without.
      Dim u32LeNone As New
 UTF32Encoding()
      Dim u32BeNone As New
 UTF32Encoding(True, False)
      Dim u32LeBom As New
 UTF32Encoding(False, True)
      Dim u32BeBom As New
 UTF32Encoding(True, True)

      ' Display the preamble for each instance.
      PrintHexBytes(u32LeNone.GetPreamble())
      PrintHexBytes(u32BeNone.GetPreamble())
      PrintHexBytes(u32LeBom.GetPreamble())
      PrintHexBytes(u32BeBom.GetPreamble())

   End Sub 'Main


   Public Shared Sub PrintHexBytes(bytes()
 As Byte)

      If bytes Is Nothing
 OrElse bytes.Length = 0 Then
         Console.WriteLine("<none>")
      Else
         Dim i As Integer
         For i = 0 To bytes.Length - 1
            Console.Write("{0:X2} ", bytes(i))
         Next i
         Console.WriteLine()
      End If

   End Sub 'PrintHexBytes 

End Class 'SamplesUTF32Encoding


'This code produces the following output.
'
'&lt;none&gt;
'&lt;none&gt;
'FF FE 00 00
'00 00 FE FF

using System;
using System.Text;

public class SamplesUTF32Encoding  {

   public static void Main()
  {

      // Create instances of UTF32Encoding, with the byte order mark
 and without.
      UTF32Encoding u32LeNone = new UTF32Encoding();
      UTF32Encoding u32BeNone = new UTF32Encoding( true,
 false );
      UTF32Encoding u32LeBom  = new UTF32Encoding( false,
 true );
      UTF32Encoding u32BeBom  = new UTF32Encoding( true,
 true );

      // Display the preamble for each instance.
      PrintHexBytes( u32LeNone.GetPreamble() );
      PrintHexBytes( u32BeNone.GetPreamble() );
      PrintHexBytes( u32LeBom.GetPreamble() );
      PrintHexBytes( u32BeBom.GetPreamble() );

   }

   public static void PrintHexBytes(
 byte[] bytes )  {

      if (( bytes == null ) || ( bytes.Length
 == 0 ))
         Console.WriteLine( "<none>" );
      else  {
         for ( int i = 0; i < bytes.Length;
 i++ )
            Console.Write( "{0:X2} ", bytes[i] );
         Console.WriteLine();
      }

   }

}


/* 
This code produces the following output.

&lt;none&gt;
&lt;none&gt;
FF FE 00 00
00 00 FE FF

*/

using namespace System;
using namespace System::Text;
void PrintHexBytes( array<Byte>^bytes );
int main()
{
   
   // Create instances of UTF32Encoding, with the byte order mark and
 without.
   UTF32Encoding ^ u32LeNone = gcnew UTF32Encoding;
   UTF32Encoding ^ u32BeNone = gcnew UTF32Encoding( true,false
 );
   UTF32Encoding ^ u32LeBom = gcnew UTF32Encoding( false,true
 );
   UTF32Encoding ^ u32BeBom = gcnew UTF32Encoding( true,true
 );
   
   // Display the preamble for each instance.
   PrintHexBytes( u32LeNone->GetPreamble() );
   PrintHexBytes( u32BeNone->GetPreamble() );
   PrintHexBytes( u32LeBom->GetPreamble() );
   PrintHexBytes( u32BeBom->GetPreamble() );
}

void PrintHexBytes( array<Byte>^bytes )
{
   if ( (bytes == nullptr) || (bytes->Length == 0) )
      Console::WriteLine( "<none>" );
   else
   {
      for ( int i = 0; i < bytes->Length;
 i++ )
         Console::Write( "{0:X2} ", bytes[ i ] );
      Console::WriteLine();
   }
}

/* 
This code produces the following output.

&lt;none&gt;
&lt;none&gt;
FF FE 00 00
00 00 FE FF

*/
import System.*;
import System.Text.*;

public class SamplesUTF32Encoding
{
    public static void main(String[]
 args)
    {
        // Create instances of UTF32Encoding, with the byte 
        // order mark and without.
        UTF32Encoding u32LeNone = new UTF32Encoding();
        UTF32Encoding u32BeNone = new UTF32Encoding(true,
 false);
        UTF32Encoding u32LeBom = new UTF32Encoding(false,
 true);
        UTF32Encoding u32BeBom = new UTF32Encoding(true,
 true);

        // Display the preamble for each instance.
        PrintHexBytes(u32LeNone.GetPreamble());
        PrintHexBytes(u32BeNone.GetPreamble());
        PrintHexBytes(u32LeBom.GetPreamble());
        PrintHexBytes(u32BeBom.GetPreamble());
    } //main
   
    public static void PrintHexBytes(ubyte
 bytes[])
    {
        if(bytes == null || bytes.length ==
 0) {
            Console.WriteLine("<none>");
        }
        else {
            for(int i = 0; i < bytes.length;
 i++) {
                Console.Write("{0:X2} ", 
                    ((System.Byte)bytes[i]).ToString("X2"));
            }
            Console.WriteLine();
        }
    } //PrintHexBytes
} //SamplesUTF32Encoding

/* 
This code produces the following output.

FF FE 00 00
<none>
FF FE 00 00
00 00 FE FF

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



UTF32Encoding.GetPreamble メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS