UnicodeEncoding.GetChars 메서드

정의

바이트 시퀀스를 문자 집합으로 디코딩합니다.

오버로드

GetChars(Byte*, Int32, Char*, Int32)

지정한 바이트 포인터에서 시작하는 바이트 시퀀스를 지정한 문자 포인터에서 시작하여 저장되는 문자 집합으로 디코딩합니다.

GetChars(Byte[], Int32, Int32, Char[], Int32)

지정한 바이트 배열의 바이트 시퀀스를 지정한 문자 배열로 디코딩합니다.

GetChars(Byte*, Int32, Char*, Int32)

중요

이 API는 CLS 규격이 아닙니다.

지정한 바이트 포인터에서 시작하는 바이트 시퀀스를 지정한 문자 포인터에서 시작하여 저장되는 문자 집합으로 디코딩합니다.

public:
 override int GetChars(System::Byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
public override int GetChars (byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public override int GetChars (byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetChars (byte* bytes, int byteCount, char* chars, int charCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetChars (byte* bytes, int byteCount, char* chars, int charCount);
[<System.CLSCompliant(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int

매개 변수

bytes
Byte*

디코딩할 첫 번째 바이트를 가리키는 포인터입니다.

byteCount
Int32

디코딩할 바이트 수입니다.

chars
Char*

결과 문자 집합을 쓰기 시작할 위치를 가리키는 포인터입니다.

charCount
Int32

쓸 최대 문자 수입니다.

반환

Int32

chars 매개 변수가 가리키는 위치에 쓴 실제 문자 수입니다.

특성

예외

bytesnull(Nothing)입니다.

또는 charsnull(Nothing)입니다.

byteCount 또는 charCount가 0보다 작습니다.

오류 검색이 사용되고 bytes에 잘못된 바이트 시퀀스를 포함합니다.

또는 charCount가 결과 문자 수보다 작은 경우

대체가 발생했습니다(자세한 내용은 .NET의 문자 인코딩 참조). 및 DecoderFallbackDecoderExceptionFallback로 설정됩니다.

설명

정확한 배열 크기를 계산 하려면 GetChars 애플리케이션에서는 결과 문자를 저장 하는 데 필요한 GetCharCount합니다. 최대 배열 크기를 계산 하려면 애플리케이션을 사용할지 GetMaxCharCount합니다. 메서드는 GetCharCount 일반적으로 더 적은 메모리를 할당하지만 메서드는 GetMaxCharCount 일반적으로 더 빠르게 실행됩니다.

오류 검색 시퀀스가 잘못되면 이 메서드가 .를 throw합니다 ArgumentException. 오류 검색이 없으면 잘못된 시퀀스가 무시되고 예외가 throw되지 않습니다.

디코딩할 바이트 범위가 BOM(바이트 순서 표시)을 포함하고 바이트 배열이 BOM 인식이 아닌 형식의 메서드에 의해 반환된 경우 U+FFFE 문자는 이 메서드에서 반환된 문자 배열에 포함됩니다. 메서드를 String.TrimStart 호출하여 제거할 수 있습니다.

스트림에서 읽은 데이터와 같이 변환할 데이터는 순차 블록에서만 사용할 수 있습니다. 이 경우 애플리케이션 데이터의 양이 너무 커서 작은 블록으로 나눌 필요가 있는 경우를 사용 해야 합니다 Decoder 또는 Encoder 에서 제공 하는 개체를 GetDecoder 또는 GetEncoder 메서드를 각각.

추가 정보

적용 대상

GetChars(Byte[], Int32, Int32, Char[], Int32)

지정한 바이트 배열의 바이트 시퀀스를 지정한 문자 배열로 디코딩합니다.

public:
 override int GetChars(cli::array <System::Byte> ^ bytes, int byteIndex, int byteCount, cli::array <char> ^ chars, int charIndex);
public override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
override this.GetChars : byte[] * int * int * char[] * int -> int
Public Overrides Function GetChars (bytes As Byte(), byteIndex As Integer, byteCount As Integer, chars As Char(), charIndex As Integer) As Integer

매개 변수

bytes
Byte[]

디코딩할 바이트 시퀀스를 포함하는 바이트 배열입니다.

byteIndex
Int32

디코딩할 첫 번째 바이트의 인덱스입니다.

byteCount
Int32

디코딩할 바이트 수입니다.

chars
Char[]

결과 문자 집합을 포함할 문자 배열입니다.

charIndex
Int32

결과 문자 집합을 쓰기 시작할 인덱스입니다.

반환

Int32

chars에 쓴 실제 문자 수입니다.

예외

bytesnull(Nothing)입니다.

또는 charsnull(Nothing)입니다.

byteIndex, byteCount 또는 charIndex가 0보다 작은 경우

또는 byteindexbyteCountbytes에서 올바른 범위를 나타내지 않습니다.

또는 charIndexchars의 유효한 인덱스가 아닌 경우

오류 검색이 사용되고 bytes에 잘못된 바이트 시퀀스를 포함합니다.

또는 chars의 용량(charIndex ~ 배열 끝)이 부족해서 결과 문자를 수용할 수 없는 경우

대체가 발생했습니다(자세한 내용은 .NET의 문자 인코딩 참조). 및 DecoderFallbackDecoderExceptionFallback로 설정됩니다.

예제

다음 예제에서는 메서드를 사용하여 GetChars 바이트 배열의 요소 범위를 디코딩하고 결과를 문자 배열에 저장하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
   array<Char>^chars;
   array<Byte>^bytes = {85,0,110,0,105,0,99,0,111,0,100,0,101,0};
   UnicodeEncoding^ Unicode = gcnew UnicodeEncoding;
   int charCount = Unicode->GetCharCount( bytes, 2, 8 );
   chars = gcnew array<Char>(charCount);
   int charsDecodedCount = Unicode->GetChars( bytes, 2, 8, chars, 0 );
   Console::WriteLine( "{0} characters used to decode bytes.", charsDecodedCount );
   Console::Write( "Decoded chars: " );
   IEnumerator^ myEnum = chars->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Char c = safe_cast<Char>(myEnum->Current);
      Console::Write( "[{0}]", c.ToString() );
   }

   Console::WriteLine();
}
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {
            85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0
        };

        UnicodeEncoding Unicode = new UnicodeEncoding();

        int charCount = Unicode.GetCharCount(bytes, 2, 8);
        chars = new Char[charCount];
        int charsDecodedCount = Unicode.GetChars(bytes, 2, 8, chars, 0);

        Console.WriteLine(
            "{0} characters used to decode bytes.", charsDecodedCount
        );

        Console.Write("Decoded chars: ");
        foreach (Char c in chars) {
            Console.Write("[{0}]", c);
        }
        Console.WriteLine();
    }
}
Imports System.Text

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        Dim chars() As Char
        Dim bytes() As Byte = {85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0}
        
        Dim uni As New UnicodeEncoding()
        
        Dim charCount As Integer = uni.GetCharCount(bytes, 2, 8)
        chars = New Char(charCount - 1) {}
        Dim charsDecodedCount As Integer = uni.GetChars(bytes, 2, 8, chars, 0)
        
        Console.WriteLine("{0} characters used to decode bytes.", charsDecodedCount)
        
        Console.Write("Decoded chars: ")
        Dim c As Char
        For Each c In  chars
            Console.Write("[{0}]", c)
        Next c
        Console.WriteLine()
    End Sub
End Class

설명

에 필요한 정확한 배열 크기를 계산 하려면 GetChars 애플리케이션에서는 결과 문자를 저장 하려면 GetCharCount합니다. 최대 배열 크기를 계산 하려면 애플리케이션을 사용할지 GetMaxCharCount합니다. 메서드는 GetCharCount 일반적으로 더 적은 메모리를 할당하지만 메서드는 GetMaxCharCount 일반적으로 더 빠르게 실행됩니다.

오류 검색 시퀀스가 잘못되면 이 메서드가 .를 throw합니다 ArgumentException. 오류 검색이 없으면 잘못된 시퀀스가 무시되고 예외가 throw되지 않습니다.

디코딩할 바이트 범위가 BOM(바이트 순서 표시)을 포함하고 바이트 배열이 BOM 인식이 아닌 형식의 메서드에 의해 반환된 경우 U+FFFE 문자는 이 메서드에서 반환된 문자 배열에 포함됩니다. 메서드를 String.TrimStart 호출하여 제거할 수 있습니다.

스트림에서 읽은 데이터와 같이 변환할 데이터는 순차 블록에서만 사용할 수 있습니다. 이 경우 애플리케이션 데이터의 양이 너무 커서 작은 블록으로 나눌 필요가 있는 경우를 사용 해야 합니다 Decoder 또는 Encoder 제공한를 GetDecoder 메서드 또는 GetEncoder 메서드를 각각.

추가 정보

적용 대상