UnicodeEncoding 생성자

정의

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다.

오버로드

UnicodeEncoding()

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다.

UnicodeEncoding(Boolean, Boolean)

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다. 매개 변수를 사용하여 big endian 바이트 순서를 사용할지 여부와 GetPreamble() 메서드를 통해 유니코드 바이트 순서 표시를 반환할지 여부를 지정할 수 있습니다.

UnicodeEncoding(Boolean, Boolean, Boolean)

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다. 매개 변수를 사용하여 big endian 바이트 순서를 사용할지 여부, 유니코드 바이트 순서 표시를 제공할지 여부 및 잘못된 인코딩이 검색되었을 때 예외를 발생시킬지 여부를 지정할 수 있습니다.

UnicodeEncoding()

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다.

public:
 UnicodeEncoding();
public UnicodeEncoding ();
Public Sub New ()

예제

다음 예제에서는 새 UnicodeEncoding 인스턴스를 만들고 인코딩의 이름을 표시하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
int main()
{
   UnicodeEncoding^ unicode = gcnew UnicodeEncoding;
   String^ encodingName = unicode->EncodingName;
   Console::WriteLine( "Encoding name: {0}", encodingName );
}
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        UnicodeEncoding unicode = new UnicodeEncoding();
        String encodingName = unicode.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}
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
End Class

설명

이 생성자는 little endian 바이트 순서를 사용하고 유니코드 바이트 순서 표시를 제공하며 잘못된 인코딩이 검색될 때 예외를 throw하지 않는 인스턴스를 만듭니다.

주의

보안상의 이유로 생성자를 호출하고 해당 인수를 UnicodeEncoding(Boolean, Boolean, Boolean) .로 설정하여 오류 검색을 throwOnInvalidBytes true사용하도록 설정해야 합니다.

적용 대상

UnicodeEncoding(Boolean, Boolean)

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다. 매개 변수를 사용하여 big endian 바이트 순서를 사용할지 여부와 GetPreamble() 메서드를 통해 유니코드 바이트 순서 표시를 반환할지 여부를 지정할 수 있습니다.

public:
 UnicodeEncoding(bool bigEndian, bool byteOrderMark);
public UnicodeEncoding (bool bigEndian, bool byteOrderMark);
new System.Text.UnicodeEncoding : bool * bool -> System.Text.UnicodeEncoding
Public Sub New (bigEndian As Boolean, byteOrderMark As Boolean)

매개 변수

bigEndian
Boolean

big endian 바이트 순서(최상위 바이트 먼저)를 사용하려면 true이고, little endian 바이트 순서(최하위 바이트 먼저)를 사용하려면 false입니다.

byteOrderMark
Boolean

GetPreamble() 메서드를 통해 유니코드 바이트 순서 표시를 반환하도록 지정하려면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 little endian 또는 big endian 바이트 순서 및 유니코드 바이트 순서 표시를 지원할지 여부를 지정하는 새 UnicodeEncoding 인스턴스를 만드는 방법을 보여 줍니다.

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 ) );
}
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")
        );
    }
}
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

설명

이 생성자는 잘못된 인코딩이 검색될 때 예외를 throw하지 않는 인스턴스를 만듭니다.

주의

보안상의 이유로 생성자를 호출하고 해당 인수를 UnicodeEncoding(Boolean, Boolean, Boolean) .로 설정하여 오류 검색을 throwOnInvalidBytes true사용하도록 설정해야 합니다.

매개 변수는 byteOrderMark 메서드의 작업을 제어합니다 GetPreamble . 이 경우 true메서드는 UTF-16 형식으로 BOM(유니코드 바이트 순서 표시)이 포함된 바이트 배열을 반환합니다. 이 경우 false길이가 0인 바이트 배열을 반환합니다. 그러나 설정 byteOrderMark true 은 메서드가 GetBytes 바이트 배열의 시작 부분에 BOM을 접두사로 지정하지 않으며 메서드가 BOM의 바이트 수를 바이트 수에 포함시키지 않습니다 GetByteCount .

추가 정보

적용 대상

UnicodeEncoding(Boolean, Boolean, Boolean)

UnicodeEncoding 클래스의 새 인스턴스를 초기화합니다. 매개 변수를 사용하여 big endian 바이트 순서를 사용할지 여부, 유니코드 바이트 순서 표시를 제공할지 여부 및 잘못된 인코딩이 검색되었을 때 예외를 발생시킬지 여부를 지정할 수 있습니다.

public:
 UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes);
public UnicodeEncoding (bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes);
new System.Text.UnicodeEncoding : bool * bool * bool -> System.Text.UnicodeEncoding
Public Sub New (bigEndian As Boolean, byteOrderMark As Boolean, throwOnInvalidBytes As Boolean)

매개 변수

bigEndian
Boolean

big endian 바이트 순서(최상위 바이트 먼저)를 사용하려면 true이고, little endian 바이트 순서(최하위 바이트 먼저)를 사용하려면 false입니다.

byteOrderMark
Boolean

GetPreamble() 메서드를 통해 유니코드 바이트 순서 표시를 반환하도록 지정하려면 true이고, 그렇지 않으면 false입니다.

throwOnInvalidBytes
Boolean

잘못된 인코딩이 검색되었을 때 예외가 발생하도록 지정하려면 true이고, 그러지 않으면 false입니다.

예제

다음 예제에서는 오류 검색을 사용 하 고 사용 하지 않고 둘 다의 UnicodeEncoding동작을 보여 줍니다.

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();
}
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();
   }
}
Imports System.Text

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


   ' 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

End Class

설명

매개 변수는 byteOrderMark 메서드의 작업을 제어합니다 GetPreamble . 이 경우 true메서드는 UTF-16 형식으로 BOM(유니코드 바이트 순서 표시)이 포함된 바이트 배열을 반환합니다. 이 경우 false길이가 0인 바이트 배열을 반환합니다. 그러나 설정 byteOrderMark true 은 메서드가 GetBytes 바이트 배열의 시작 부분에 BOM을 접두사로 지정하지 않으며 메서드가 BOM의 바이트 수를 바이트 수에 포함시키지 않습니다 GetByteCount .

매개 변수인 throwOnInvalidBytes true경우 잘못된 바이트 시퀀스를 검색하는 메서드가 throw됩니다 System.ArgumentException. 그렇지 않으면 메서드가 예외를 throw하지 않고 잘못된 시퀀스가 무시됩니다.

주의

보안상의 이유로 이 생성자를 사용하여 클래스의 UnicodeEncoding 인스턴스를 만들고 다음으로 설정 throwOnInvalidBytes 하여 오류 검색을 true켜야 합니다.

추가 정보

적용 대상