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

Dim instance As Encoding Dim returnValue As Byte() returnValue = instance.GetPreamble
使用するエンコーディングを指定するバイト シーケンスを格納するバイト配列。 または プリアンブルが不要な場合は、長さ 0 のバイト配列。

UTF-16 エンコーダおよび UTF-32 エンコーダでは、最上位バイトが先頭に配置されるビッグ エンディアン バイト順、または最下位バイトが先頭に配置されるリトル エンディアン バイト順が使用されます。たとえば、アルファベットの大文字 A (U+0041) は次のように 16 進数でシリアル化されます。
-
UTF-16 ビッグ エンディアン バイト順 : 00 41
-
UTF-16 リトル エンディアン バイト順 : 41 00
Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (Unicode では、コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、次のように 16 進数でシリアル化されます。
-
UTF-16 ビッグ エンディアン バイト順 : FE FF
-
UTF-16 リトル エンディアン バイト順 : FF FE
通常、ネイティブなバイト順で Unicode 文字を格納した方が効率的です。たとえば、Intel のコンピュータなど、リトル エンディアンのプラットフォームでは、リトル エンディアンのバイト順を使用した方が効率的です。
バイト順とバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。
![]() |
---|
エンコード済みバイトを正しくデコードするには、エンコード済みバイトの前にプリアンブルを付加します。ただし、ほとんどのエンコーディングではプリアンブルが付加されません。エンコード済みバイトを正しくデコードするには、Unicode エンコーディング (UTF8Encoding、UnicodeEncoding、または UTF32Encoding) をプリアンブルと共に使用します。 |

次のコード例は、プリアンブルに基づいてエンコーディングのバイト順を決定しています。
Imports System Imports System.Text Namespace GetPreambleExample Class GetPreambleExampleClass Shared Sub Main() Dim [unicode] As Encoding = Encoding.Unicode ' Get the preamble for the Unicode encoder. ' In this case the preamble contains the byte order mark (BOM). Dim preamble As Byte() = [unicode].GetPreamble() ' Make sure a preamble was returned ' and is large enough to contain a BOM. If preamble.Length >= 2 Then If preamble(0) = &HFE And preamble(1) = &HFF Then Console.WriteLine("The Unicode encoder is encoding in big-endian order.") Else If preamble(0) = &HFF And preamble(1) = &HFE Then Console.WriteLine("The Unicode encoder is encoding in little-endian order.") End If End If End If End Sub End Class End Namespace
using System; using System.Text; namespace GetPreambleExample { class GetPreambleExampleClass { static void Main() { Encoding unicode = Encoding.Unicode; // Get the preamble for the Unicode encoder. // In this case the preamble contains the byte order mark (BOM). byte[] preamble = unicode.GetPreamble(); // Make sure a preamble was returned // and is large enough to containa BOM. if(preamble.Length >= 2) { if(preamble[0] == 0xFE && preamble[1] == 0xFF) { Console.WriteLine("The Unicode encoder is encoding in big-endian order."); } else if(preamble[0] == 0xFF && preamble[1] == 0xFE) { Console.WriteLine("The Unicode encoder is encoding in little-endian order."); } } } } }
using namespace System; using namespace System::Text; int main() { Encoding^ unicode = Encoding::Unicode; // Get the preamble for the Unicode encoder. // In this case the preamblecontains the Byte order mark (BOM). array<Byte>^preamble = unicode->GetPreamble(); // Make sure a preamble was returned // and is large enough to containa BOM. if ( preamble->Length >= 2 ) { // if (preamble->Item[0] == 0xFE && preamble->Item[1] == 0xFF) if ( preamble[ 0 ] == 0xFE && preamble[ 1 ] == 0xFF ) { Console::WriteLine( "The Unicode encoder is encoding in big-endian order." ); } // else if (preamble->Item[0] == 0xFF && preamble->Item[1] == 0xFE) else // else if (preamble->Item[0] == 0xFF && preamble->Item[1] == 0xFE) if ( preamble[ 0 ] == 0xFF && preamble[ 1 ] == 0xFE ) { Console::WriteLine( "The Unicode encoder is encoding in little-endian order." ); } } }
package GetPreambleExample; import System.*; import System.Text.*; class GetPreambleExampleClass { public static void main(String[] args) { Encoding unicode = Encoding.get_Unicode(); // Get the preamble for the Unicode encoder. // In this case the preamble contains the byte order mark (BOM). ubyte preamble[] = unicode.GetPreamble(); // Make sure a preamble was returned // and is large enough to containa BOM. if(preamble.length >= 2) { if(preamble[0] == 0xFE && preamble[1] == 0xFF) { Console.WriteLine("The Unicode encoder is " + "encoding in big-endian order."); } else { if(preamble[0] == 0xFF && preamble[1] == 0xFE) { Console.WriteLine("The Unicode encoder is" + " encoding in little-endian order."); } } } } //main } //GetPreambleExampleClass

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に収録されているすべての辞書からEncoding.GetPreamble メソッドを検索する場合は、下記のリンクをクリックしてください。

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