UnicodeEncoding コンストラクタとは? わかりやすく解説

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

UnicodeEncoding コンストラクタ (Boolean, Boolean)

UnicodeEncoding クラス新しインスタンス初期化します。パラメータでは、ビッグ エンディアン バイト順を使用するかどうか、および Unicode バイト順マーク付加するかどうか指定します

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

解説解説

このコンストラクタは、無効なエンコーディング検出したときに例外スローしないインスタンス作成します

注意に関するメモ注意

セキュリティ上の理由から、throwOnInvalidBytes パラメータ受け取コンストラクタ使用して、このパラメータtrue設定することにより、エラー検出有効にすることをお勧めます。

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

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

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

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

使用例使用例

次のコード例は、リトル エンディアンまたはビッグ エンディアンのどちらのバイト順をサポートするか、および Unicode バイト順マークサポートするかどうか指定して新しUnicodeEncoding インスタンス作成する方法示してます。UnicodeEncoding インスタンス動作は、bigEndian パラメータbyteOrderMark パラメータの値によって異なります

Imports System
Imports System.Text

Class UnicodeEncodingExample
    
    Public Shared Sub Main()

        ' Create a UnicodeEncoding without parameters.
        Dim unicodeDefault As New
 UnicodeEncoding()

        ' Create a UnicodeEncoding to support little-endian byte ordering
        ' and include the Unicode byte order mark.        
        Dim unicodeLittleEndianBOM As New
 UnicodeEncoding(False, True)
        ' Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicodeDefault.Equals(unicodeLittleEndianBOM))
        
        ' Create a UnicodeEncoding to support little-endian byte ordering
        ' and not include the Unicode byte order mark.
        Dim unicodeLittleEndianNoBOM As New
 UnicodeEncoding(False, False)
        ' Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicodeDefault.Equals(unicodeLittleEndianNoBOM))
        
        ' Create a UnicodeEncoding to support big-endian byte ordering
        ' and include the Unicode byte order mark.
        Dim unicodeBigEndianBOM As New
 UnicodeEncoding(True, True)
        ' Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicodeDefault.Equals(unicodeBigEndianBOM))
        
        ' Create a UnicodeEncoding to support big-endian byte ordering
        ' and not include the Unicode byte order mark.
        Dim unicodeBigEndianNoBOM As New
 UnicodeEncoding(True, False)
        ' Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicodeDefault.Equals(unicodeBigEndianNoBOM))
    End Sub
    
    
    Public Shared Sub DescribeEquivalence(isEquivalent
 As Boolean)
        Dim phrase as String
        If isEquivalent Then
            phrase = "An"
        Else
            phrase = "Not an"
        End If
        Console.WriteLine("{0} equivalent encoding.",
 phrase)
    End Sub
End Class
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main()
 {

        // Create a UnicodeEncoding without parameters.
        UnicodeEncoding unicode = new UnicodeEncoding();

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianBOM = 
            new UnicodeEncoding(false, true);
        // Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicode.Equals(unicodeLittleEndianBOM));

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and not include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianNoBOM =
            new UnicodeEncoding(false, false);
        // Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicode.Equals(unicodeLittleEndianNoBOM));

        // Create a UnicodeEncoding to support big-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeBigEndianBOM =
            new UnicodeEncoding(true, true);
        // Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicode.Equals(unicodeBigEndianBOM));

        // Create a UnicodeEncoding to support big-endian byte ordering
        // and not include the Unicode byte order mark.
        UnicodeEncoding unicodeBigEndianNoBOM =
            new UnicodeEncoding(true, false);
        // Compare this UnicodeEncoding to the UnicodeEncoding without
 parameters.
        DescribeEquivalence(unicode.Equals(unicodeBigEndianNoBOM));
    }

    public static void DescribeEquivalence(Boolean
 isEquivalent) {
        Console.WriteLine(
            "{0} equivalent encoding.", (isEquivalent ? "An"
 : "Not an")
        );
    }
}
using namespace System;
using namespace System::Text;
void DescribeEquivalence( Boolean isEquivalent )
{
   Console::WriteLine( " {0} equivalent encoding.", (isEquivalent ? (String^)"An"
 : "Not an") );
}

int main()
{
   
   // Create a UnicodeEncoding without parameters.
   UnicodeEncoding^ unicode = gcnew UnicodeEncoding;
   
   // Create a UnicodeEncoding to support little-endian Byte ordering
   // and include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeLittleEndianBOM = gcnew UnicodeEncoding( false,true
 );
   
   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeLittleEndianBOM ) );
   
   // Create a UnicodeEncoding to support little-endian Byte ordering
   // and not include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeLittleEndianNoBOM = gcnew UnicodeEncoding( false,false
 );
   
   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeLittleEndianNoBOM ) );
   
   // Create a UnicodeEncoding to support big-endian Byte ordering
   // and include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeBigEndianBOM = gcnew UnicodeEncoding( true,true
 );
   
   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeBigEndianBOM ) );
   
   // Create a UnicodeEncoding to support big-endian Byte ordering
   // and not include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeBigEndianNoBOM = gcnew UnicodeEncoding( true,false
 );
   
   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeBigEndianNoBOM ) );
}

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

class UnicodeEncodingExample
{
    public static void main(String[]
 args)
    {
        // Create a UnicodeEncoding without parameters.
        UnicodeEncoding unicode = new UnicodeEncoding();

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianBOM = new 
            UnicodeEncoding(false, true);

        // Compare this UnicodeEncoding to the
        // UnicodeEncoding without parameters.
        DescribeEquivalence(unicode.Equals(unicodeLittleEndianBOM));

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and not include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianNoBOM = new 
            UnicodeEncoding(false, false);

        // Compare this UnicodeEncoding to the UnicodeEncoding 
        // without parameters.
        DescribeEquivalence(unicode.Equals(unicodeLittleEndianNoBOM));

        // Create a UnicodeEncoding to support big-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeBigEndianBOM = new UnicodeEncoding(true,
 true);

        // Compare this UnicodeEncoding to the
        // UnicodeEncoding without parameters.
        DescribeEquivalence(unicode.Equals(unicodeBigEndianBOM));

        // Create a UnicodeEncoding to support big-endian byte ordering
        // and not include the Unicode byte order mark.
        UnicodeEncoding unicodeBigEndianNoBOM = new 
            UnicodeEncoding(true, false);

        // Compare this UnicodeEncoding to the
        // UnicodeEncoding without parameters.
        DescribeEquivalence(unicode.Equals(unicodeBigEndianNoBOM));
    } //main

    public static void DescribeEquivalence(boolean
 isEquivalent)
    {
        Console.WriteLine("{0} equivalent encoding.",
            (isEquivalent) ? "An" : "Not an");
    } //DescribeEquivalence
} //UnicodeEncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UnicodeEncoding クラス
UnicodeEncoding メンバ
System.Text 名前空間
GetPreamble

UnicodeEncoding コンストラクタ (Boolean, Boolean, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

UnicodeEncoding クラス新しインスタンス初期化します。パラメータでは、ビッグ エンディアン バイト順を使用するかどうかUnicode バイト順マーク付加するかどうか、および無効なエンコーディング検出したときに例外スローするかどうか指定します

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

解説解説

throwOnInvalidBytes パラメータtrue場合無効なバイト シーケンス検出したメソッドは System.ArgumentException をスローます。それ以外場合は、例外スローせず、無効なシーケンス無視します。

注意に関するメモ注意

セキュリティ上の理由から、このコンストラクタ使用して UnicodeEncoding クラスインスタンス作成しthrowOnInvalidBytestrue設定することでエラー検出オンにすることをお勧めます。

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

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

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

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

使用例使用例

次のコード例は、エラー検出有効にした場合無効にした場合UnicodeEncoding動作示します

Imports System
Imports System.Text
Imports Microsoft.VisualBasic

Public Class SamplesUnicodeEncoding   

   Public Shared Sub Main()

      ' Create an instance of UnicodeEncoding using little-endian byte
 order.
      ' This will be used for encoding.
      Dim u16LE As New UnicodeEncoding(False,
 True)

      ' Create two instances of UnicodeEncoding using big-endian byte
 order: one with error detection and one without.
      ' These will be used for decoding.
      Dim u16withED As New
 UnicodeEncoding(True, True, True)
      Dim u16noED As New
 UnicodeEncoding(True, True, False)

      ' Create byte arrays from the same string containing the following
 characters:
      '    Latin Small Letter Z (U+007A)
      '    Latin Small Letter A (U+0061)
      '    Combining Breve (U+0306)
      '    Latin Small Letter AE With Acute (U+01FD)
      '    Greek Small Letter Beta (U+03B2)
      '    Latin Capital Letter U with  Diaeresis (U+00DC)
      Dim myStr As String
 = "za" & ChrW(&H0306) & ChrW(&H01FD)
 & ChrW(&H03B2) & ChrW(&H00DC)

      ' Encode the string using little-endian byte order.
      Dim myBytes(u16LE.GetByteCount(myStr)) As
 Byte
      u16LE.GetBytes(myStr, 0, myStr.Length, myBytes, 0)

      ' Decode the byte array with error detection.
      Console.WriteLine("Decoding with error detection:")
      PrintDecodedString(myBytes, u16withED)

      ' Decode the byte array without error detection.
      Console.WriteLine("Decoding without error detection:")
      PrintDecodedString(myBytes, u16noED)

   End Sub 'Main


   ' Decode the bytes and display the string.
   Public Shared Sub PrintDecodedString(bytes()
 As Byte, enc As Encoding)

      Try
         Console.WriteLine("   Decoded string: {0}",
 enc.GetString(bytes, 0, bytes.Length))
      Catch e As System.ArgumentException
         Console.WriteLine(e.ToString())
      End Try

      Console.WriteLine()

   End Sub 'PrintDecodedString
 

End Class 'SamplesUnicodeEncoding

using System;
using System.Text;

public class SamplesUnicodeEncoding  {

   public static void Main()
  {

      // Create an instance of UnicodeEncoding using little-endian byte
 order.
      // This will be used for encoding.
      UnicodeEncoding u16LE     = new UnicodeEncoding( false,
 true );

      // Create two instances of UnicodeEncoding using big-endian byte
 order: one with error detection and one without.
      // These will be used for decoding.
      UnicodeEncoding u16withED = new UnicodeEncoding( true,
 true, true );
      UnicodeEncoding u16noED   = new UnicodeEncoding( true,
 true, false );

      // Create byte arrays from the same string containing the following
 characters:
      //    Latin Small Letter Z (U+007A)
      //    Latin Small Letter A (U+0061)
      //    Combining Breve (U+0306)
      //    Latin Small Letter AE With Acute (U+01FD)
      //    Greek Small Letter Beta (U+03B2)
      //    Latin Capital Letter U with  Diaeresis (U+00DC)
      String myStr = "za\u0306\u01FD\u03B2\u00DC";

      // Encode the string using little-endian byte order.
      byte[] myBytes = new byte[u16LE.GetByteCount( myStr )];
      u16LE.GetBytes( myStr, 0, myStr.Length, myBytes, 0 );

      // Decode the byte array with error detection.
      Console.WriteLine( "Decoding with error detection:" );
      PrintDecodedString( myBytes, u16withED );

      // Decode the byte array without error detection.
      Console.WriteLine( "Decoding without error detection:" );
      PrintDecodedString( myBytes, u16noED );

   }


   // Decode the bytes and display the string.
   public static void PrintDecodedString(
 byte[] bytes, Encoding enc )  {

      try  {
         Console.WriteLine( "   Decoded string: {0}",
 enc.GetString( bytes, 0, bytes.Length ) );
      }
      catch ( System.ArgumentException e )  {
         Console.WriteLine( e.ToString() );
      }

      Console.WriteLine();

   }

}

using namespace System;
using namespace System::Text;
void PrintDecodedString( array<Byte>^bytes, Encoding^ enc
 );
int main()
{
   
   // Create an instance of UnicodeEncoding using little-endian byte
 order.
   // This will be used for encoding.
   UnicodeEncoding^ u16LE = gcnew UnicodeEncoding( false,true
 );
   
   // Create two instances of UnicodeEncoding using big-endian byte
 order: one with error detection and one without.
   // These will be used for decoding.
   UnicodeEncoding^ u16withED = gcnew UnicodeEncoding( true,true,true
 );
   UnicodeEncoding^ u16noED = gcnew UnicodeEncoding( true,true,false
 );
   
   // Create byte arrays from the same string containing the following
 characters:
   //    Latin Small Letter Z (U+007A)
   //    Latin Small Letter A (U+0061)
   //    Combining Breve (U+0306)
   //    Latin Small Letter AE With Acute (U+01FD)
   //    Greek Small Letter Beta (U+03B2)
   //    Latin Capital Letter U with  Diaeresis (U+00DC)
   String^ myStr = "za\u0306\u01FD\u03B2\u00DC";
   
   // Encode the string using little-endian byte order.
   array<Byte>^myBytes = gcnew array<Byte>(u16LE->GetByteCount( myStr
 ));
   u16LE->GetBytes( myStr, 0, myStr->Length, myBytes, 0 );
   
   // Decode the byte array with error detection.
   Console::WriteLine( "Decoding with error detection:" );
   PrintDecodedString( myBytes, u16withED );
   
   // Decode the byte array without error detection.
   Console::WriteLine( "Decoding without error detection:" );
   PrintDecodedString( myBytes, u16noED );
}


// Decode the bytes and display the string.
void PrintDecodedString( array<Byte>^bytes, Encoding^ enc
 )
{
   try
   {
      Console::WriteLine( "   Decoded string: {0}",
 enc->GetString( bytes, 0, bytes->Length ) );
   }
   catch ( System::ArgumentException^ e ) 
   {
      Console::WriteLine( e );
   }

   Console::WriteLine();
}

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

public class SamplesUnicodeEncoding
{
    public static void main(String[]
 args)
    {
        // Create an instance of UnicodeEncoding using little-endian
 
        // byte order.
        // This will be used for encoding.
        UnicodeEncoding u16LE = new UnicodeEncoding(false,
 true);

        // Create two instances of UnicodeEncoding using big-endian
 byte 
        // order: one with error detection and one without.
        // These will be used for decoding.
        UnicodeEncoding u16withED = new UnicodeEncoding(true,
 true, true);
        UnicodeEncoding u16noED = new UnicodeEncoding(true,
 true, false);

        // Create byte arrays from the same string containing 
        // the following characters:
        //    Latin Small Letter Z (U+007A)
        //    Latin Small Letter A (U+0061)
        //    Combining Breve (U+0306)
        //    Latin Small Letter AE With Acute (U+01FD)
        //    Greek Small Letter Beta (U+03B2)
        //    Latin Capital Letter U with  Diaeresis (U+00DC)
        String myStr = "za\u0306\u01FD\u03B2\u00DC";

        // Encode the string using little-endian byte order.
        ubyte myBytes[] = new ubyte[u16LE.GetByteCount(myStr)];
        u16LE.GetBytes(myStr, 0, myStr.get_Length(), myBytes, 0);

        // Decode the byte array with error detection.
        Console.WriteLine("Decoding with error detection:");
        PrintDecodedString(myBytes, u16withED);

        // Decode the byte array without error detection.
        Console.WriteLine("Decoding without error detection:");
        PrintDecodedString(myBytes, u16noED);
    } //main

    // Decode the bytes and display the string.
    public static void PrintDecodedString(ubyte[]
 bytes, Encoding enc)
    {
        try {
            Console.WriteLine("   Decoded string: {0}",
 
                enc.GetString(bytes, 0, bytes.length));
        }
        catch(System.ArgumentException e) {
            Console.WriteLine(e.toString());
        }
        Console.WriteLine();
    } //PrintDecodedString
} //SamplesUnicodeEncoding

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UnicodeEncoding クラス
UnicodeEncoding メンバ
System.Text 名前空間
GetPreamble

UnicodeEncoding コンストラクタ


UnicodeEncoding コンストラクタ ()

UnicodeEncoding クラス新しインスタンス初期化します。

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

Dim instance As New UnicodeEncoding
public UnicodeEncoding ()
public:
UnicodeEncoding ()
public UnicodeEncoding ()
public function UnicodeEncoding ()
解説解説

このコンストラクタは、リトル エンディアン バイト順を使用しUnicode バイト順マーク付加し無効なエンコーディング検出したときに例外スローしないインスタンス作成します

注意に関するメモ注意

セキュリティ上の理由から、throwOnInvalidBytes パラメータ受け取コンストラクタ使用して、このパラメータtrue設定することにより、エラー検出有効にすることをお勧めます。

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

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

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

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

使用例使用例

次のコード例は、新しUnicodeEncoding インスタンス作成してエンコード名を表示する方法示してます。

Imports System
Imports System.Text

Class UnicodeEncodingExample

    Public Shared Sub Main()
        Dim uni As New UnicodeEncoding()
        Dim encodingName As String
 = uni.EncodingName
        Console.WriteLine("Encoding name: " &
 encodingName)
    End Sub 'Main
End Class 'UnicodeEncodingExample
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main()
 {
        UnicodeEncoding unicode = new UnicodeEncoding();
        String encodingName = unicode.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}
using namespace System;
using namespace System::Text;
int main()
{
   UnicodeEncoding^ unicode = gcnew UnicodeEncoding;
   String^ encodingName = unicode->EncodingName;
   Console::WriteLine( "Encoding name: {0}", encodingName );
}

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

class UnicodeEncodingExample
{
    public static void main(String[]
 args)
    {
        UnicodeEncoding unicode = new UnicodeEncoding();
        String encodingName = unicode.get_EncodingName();
        Console.WriteLine(("Encoding name: " + encodingName));
    } //main
} //UnicodeEncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「UnicodeEncoding コンストラクタ」の関連用語

UnicodeEncoding コンストラクタのお隣キーワード
検索ランキング

   

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



UnicodeEncoding コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS