UTF32Encoding.GetPreamble メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As UTF32Encoding Dim returnValue As Byte() returnValue = instance.GetPreamble
このインスタンスのコンストラクタでバイト順マークを付加するよう指定した場合は、Unicode バイト順マークが格納されたバイト配列。 それ以外の場合は、長さ 0 のバイト配列。

プリアンブルがエンコード済みストリームの前に付加されていると、使用されているエンコーディング形式をデコーダが識別するのに役立ちます。
エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、Latin の大文字 A (コード ポイント U+0041) は次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 00 41
-
リトル エンディアン バイト順 : 41 00 00 00
UTF32Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
ビッグ エンディアン バイト順 : 00 00 FE FF
-
リトル エンディアン バイト順 : FF FE 00 00
通常、ネイティブなバイト順で 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. ' '<none> '<none> '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. <none> <none> 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. <none> <none> 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 */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からUTF32Encoding.GetPreamble メソッドを検索する場合は、下記のリンクをクリックしてください。

- UTF32Encoding.GetPreamble メソッドのページへのリンク