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

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

UnicodeEncoding.GetPreamble メソッド

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

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

解説解説

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

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

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

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

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

注意に関するメモ注意

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

使用例使用例

次のコード例は、GetPreamble メソッドを使用して、UnicodeEncoding のインスタンスの Unicode バイト順マークをビッグエンディアン形式またはリトルエンディアン形式で返す方法を示しています。

Imports System
Imports System.Text
Imports Microsoft.VisualBasic

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        Dim byteOrderMark() As Byte
        Dim b As Byte
        
        byteOrderMark = Encoding.Unicode.GetPreamble()
        Console.WriteLine("Default (little-endian) Unicode Preamble:")
        For Each b In  byteOrderMark
            Console.Write("[{0}]", b)
        Next b
        Console.WriteLine(ControlChars.NewLine)
        
        Dim bigEndianUnicode As New
 UnicodeEncoding(True, True)
        byteOrderMark = bigEndianUnicode.GetPreamble()
        Console.WriteLine("Big-endian Unicode Preamble:")
        For Each b In  byteOrderMark
            Console.Write("[{0}]", b)
        Next b
    End Sub 'Main
End Class 'UnicodeEncodingExample
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main()
 {
        Byte[] byteOrderMark;
        
        byteOrderMark = Encoding.Unicode.GetPreamble();
        Console.WriteLine("Default (little-endian) Unicode Preamble:");
        foreach (Byte b in byteOrderMark) {
            Console.Write("[{0}]", b);
        }
        Console.WriteLine("\n");

        UnicodeEncoding bigEndianUnicode = new UnicodeEncoding(true,
 true);
        byteOrderMark = bigEndianUnicode.GetPreamble();
        Console.WriteLine("Big-endian Unicode Preamble:");
        foreach (Byte b in byteOrderMark) {
            Console.Write("[{0}]", b);
        }
    }
}
using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
   array<Byte>^byteOrderMark;
   byteOrderMark = Encoding::Unicode->GetPreamble();
   Console::WriteLine( "Default (little-endian) Unicode Preamble:" );
   IEnumerator^ myEnum = byteOrderMark->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Byte b = safe_cast<Byte>(myEnum->Current);
      Console::Write( "[{0}]", b );
   }

   Console::WriteLine( "\n" );
   UnicodeEncoding^ bigEndianUnicode = gcnew UnicodeEncoding( true,true
 );
   byteOrderMark = bigEndianUnicode->GetPreamble();
   Console::WriteLine( "Big-endian Unicode Preamble:" );
   myEnum = byteOrderMark->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Byte b = safe_cast<Byte>(myEnum->Current);
      Console::Write( "[{0}]", b );
   }
}

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

class UnicodeEncodingExample
{
    public static void main(String[]
 args)
    {
        ubyte byteOrderMark[];
        byteOrderMark = Encoding.get_Unicode().GetPreamble();
        Console.WriteLine("Default (little-endian) Unicode Preamble:");
        for(int iCtr = 0; iCtr < byteOrderMark.length;
 iCtr++) {
            ubyte b = byteOrderMark[iCtr];
            Console.Write("[{0}]", String.valueOf(b));
        }
        Console.WriteLine("\n");
        UnicodeEncoding bigEndianUnicode = new UnicodeEncoding(true,
 true);
        byteOrderMark = bigEndianUnicode.GetPreamble();
        Console.WriteLine("Big-endian Unicode Preamble:");
        for(int iCtr = 0; iCtr < byteOrderMark.length;
 iCtr++) {
            ubyte b = byteOrderMark[iCtr];
            Console.Write("[{0}]", String.valueOf(b));
        }
    } //main
} //UnicodeEncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2026 GRAS Group, Inc.RSS