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

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

UTF8Encoding は、オプションでプリアンブルを提供します。プリアンブルは、エンコーディング プロセスで得られたバイト シーケンスの先頭に付加できるバイトの配列です。プリアンブルにバイト順マーク (コード ポイント U+FEFF) が含まれる場合、デコーダはバイト順および変換形式 (UTF) を判断できます。Unicode バイト順マークは、EF BB BF (16 進数) としてシリアル化されます。GetPreamble メソッドは、バイト順マークを格納するバイト配列を返します。
Unicode エンコーディング、バイト順、およびバイト順マークの詳細については、www.unicode.org の「Unicode Standard」を参照してください。
![]() |
---|

次の例は、GetPreamble メソッドを使用して、UTF-8 形式でエンコードされた Unicode バイト順マークを返す方法を示しています。UTF8Encoding の既定のコンストラクタはプリアンブルを提供しません。
Imports System Imports System.Text Class UTF8EncodingExample Public Shared Sub Main() ' The default constructor does not provide a preamble. Dim UTF8NoPreamble As New UTF8Encoding() Dim UTF8WithPreamble As New UTF8Encoding(True) Dim preamble() As Byte preamble = UTF8NoPreamble.GetPreamble() Console.WriteLine("UTF8NoPreamble") Console.WriteLine(" preamble length: {0}", preamble.Length) Console.Write(" preamble: ") ShowArray(preamble) preamble = UTF8WithPreamble.GetPreamble() Console.WriteLine("UTF8WithPreamble") Console.WriteLine(" preamble length: {0}", preamble.Length) Console.Write(" preamble: ") ShowArray(preamble) End Sub 'Main Public Shared Sub ShowArray(theArray As Array) Dim o As Object For Each o In theArray Console.Write("[{0}]", o) Next o Console.WriteLine() End Sub 'ShowArray End Class 'UTF8EncodingExample
using System; using System.Text; class UTF8EncodingExample { public static void Main() { // The default constructor does not provide a preamble. UTF8Encoding UTF8NoPreamble = new UTF8Encoding(); UTF8Encoding UTF8WithPreamble = new UTF8Encoding(true); Byte[] preamble; preamble = UTF8NoPreamble.GetPreamble(); Console.WriteLine("UTF8NoPreamble"); Console.WriteLine(" preamble length: {0}", preamble.Length); Console.Write(" preamble: "); ShowArray(preamble); preamble = UTF8WithPreamble.GetPreamble(); Console.WriteLine("UTF8WithPreamble"); Console.WriteLine(" preamble length: {0}", preamble.Length); Console.Write(" preamble: "); ShowArray(preamble); } public static void ShowArray(Array theArray) { foreach (Object o in theArray) { Console.Write("[{0}]", o); } Console.WriteLine(); } }
using namespace System; using namespace System::Text; using namespace System::Collections; void ShowArray( Array^ theArray ) { IEnumerator^ myEnum = theArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ o = safe_cast<Object^>(myEnum->Current); Console::Write( "[{0}]", o ); } Console::WriteLine(); } int main() { // The default constructor does not provide a preamble. UTF8Encoding^ UTF8NoPreamble = gcnew UTF8Encoding; UTF8Encoding^ UTF8WithPreamble = gcnew UTF8Encoding( true ); array<Byte>^preamble; preamble = UTF8NoPreamble->GetPreamble(); Console::WriteLine( "UTF8NoPreamble" ); Console::WriteLine( " preamble length: {0}", preamble->Length ); Console::Write( " preamble: " ); ShowArray( preamble ); preamble = UTF8WithPreamble->GetPreamble(); Console::WriteLine( "UTF8WithPreamble" ); Console::WriteLine( " preamble length: {0}", preamble->Length ); Console::Write( " preamble: " ); ShowArray( preamble ); }
import System.*; import System.Text.*; class UTF8EncodingExample { public static void main(String[] args) { // The default constructor does not provide a preamble. UTF8Encoding utf8NoPreamble = new UTF8Encoding(); UTF8Encoding utf8WithPreamble = new UTF8Encoding(true); ubyte preamble[]; preamble = utf8NoPreamble.GetPreamble(); Console.WriteLine("UTF8NoPreamble"); Console.WriteLine(" preamble length: {0}", String.valueOf(preamble.length)); Console.Write(" preamble: "); ShowArray(preamble); preamble = utf8WithPreamble.GetPreamble(); Console.WriteLine("UTF8WithPreamble"); Console.WriteLine(" preamble length: {0}", String.valueOf(preamble.length)); Console.Write(" preamble: "); ShowArray(preamble); } //main public static void ShowArray(Array theArray) { Object o = null; for (int iCtr = 0; iCtr < theArray.get_Count(); iCtr++) { o = theArray.get_Item(iCtr); Console.Write("[{0}]", o); } Console.WriteLine(); } //ShowArray } //UTF8EncodingExample

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

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