UTF8Encoding.GetChars 메서드

정의

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

오버로드

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

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

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

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

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

Important

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

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

public:
 override int GetChars(System::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)]
public override int GetChars(byte* bytes, int byteCount, char* chars, int charCount);
[<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
[<System.CLSCompliant(false)>]
override this.GetChars : nativeptr<byte> * int * nativeptr<char> * int -> int

매개 변수

bytes
Byte*

디코딩할 첫 번째 바이트에 대한 포인터입니다.

byteCount
Int32

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

chars
Char*

결과 문자 집합 작성을 시작할 위치에 대한 포인터입니다.

charCount
Int32

쓸 최대 문자 수입니다.

반품

로 표시된 위치에 기록된 chars실제 문자 수입니다.

특성

예외

bytesnull입니다.

-또는-

charsnull입니다.

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

오류 검색을 사용하도록 설정하고 bytes 잘못된 바이트 시퀀스를 포함합니다.

-또는-

charCount 가 결과 문자 수보다 작습니다.

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

-그리고-

DecoderFallbackDecoderExceptionFallback로 설정됩니다.

설명

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

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

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

스트림에서 읽은 데이터와 같이 변환할 데이터는 순차적 블록에서만 사용할 수 있습니다. 이 경우 또는 데이터의 양이 너무 커서 더 작은 블록으로 나누어야 하는 경우 메서드 또는 메서드에서 제공하는 GetDecoder 개체를 GetEncoderEncoder 각각 사용합니다Decoder.

추가 정보

적용 대상

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

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

반품

로 작성된 실제 문자 수입니다 chars.

예외

bytesnull입니다.

-또는-

charsnull입니다.

byteIndex 또는 byteCountcharIndex 0보다 작습니다.

-또는-

byteIndex 에서 byteCount 유효한 범위를 bytes나타내지 않습니다.

-또는-

charIndex에서 유효한 인덱스가 아닌 경우 chars

오류 검색을 사용하도록 설정하고 bytes 잘못된 바이트 시퀀스를 포함합니다.

-또는-

chars 에는 결과 문자를 수용할 수 있는 충분한 용량 charIndex 이 없습니다.

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

-그리고-

DecoderFallbackDecoderExceptionFallback로 설정됩니다.

예제

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

using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        Char[] chars;
        Byte[] bytes = new Byte[] {
             85,  84,  70,  56,  32,  69, 110,
             99, 111, 100, 105, 110, 103,  32,
             69, 120,  97, 109, 112, 108, 101
        };

        UTF8Encoding utf8 = new UTF8Encoding();

        int charCount = utf8.GetCharCount(bytes, 2, 13);
        chars = new Char[charCount];
        int charsDecodedCount = utf8.GetChars(bytes, 2, 13, 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 UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim chars() As Char
        Dim bytes() As Byte = { _
            85,  84,  70,  56,  32,  69, 110, _
            99, 111, 100, 105, 110, 103,  32, _
            69, 120,  97, 109, 112, 108, 101 _
        }
        
        Dim utf8 As New UTF8Encoding()
        
        Dim charCount As Integer = utf8.GetCharCount(bytes, 2, 13)
        chars = New Char(charCount - 1) {}
        Dim charsDecodedCount As Integer = utf8.GetChars(bytes, 2, 13, 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 하여 제거할 수 있습니다.

스트림에서 읽은 데이터와 같이 변환할 데이터는 순차적 블록에서만 사용할 수 있습니다. 이 경우 또는 데이터의 양이 너무 커서 더 작은 블록으로 나누어야 하는 경우 메서드 또는 메서드에서 제공된 GetDecoder 값을 각각 사용합니다Decoder.GetEncoderEncoder

추가 정보

적용 대상