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

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

Encoding.GetPreamble メソッド

派生クラスオーバーライドされた場合使用するエンコーディング指定するバイト シーケンス返します

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

解説解説

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

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

通常ネイティブバイト順で 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 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Encoding.GetPreamble メソッド」の関連用語

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

   

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



Encoding.GetPreamble メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS