ASCIIEncoding.GetByteCount 메서드

정의

문자 집합을 인코딩할 경우 생성되는 바이트 수를 계산합니다.

오버로드

GetByteCount(ReadOnlySpan<Char>)

지정된 문자 범위를 인코딩하여 생성된 바이트 수를 계산합니다.

GetByteCount(String)

지정된 String의 문자를 인코딩하여 생성된 바이트 수를 계산합니다.

GetByteCount(Char*, Int32)

지정한 문자 포인터에서 시작되는 문자 집합을 인코딩할 경우 생성되는 바이트 수를 계산합니다.

GetByteCount(Char[], Int32, Int32)

지정한 문자 배열의 문자 집합을 인코딩할 경우 생성되는 바이트 수를 계산합니다.

GetByteCount(ReadOnlySpan<Char>)

지정된 문자 범위를 인코딩하여 생성된 바이트 수를 계산합니다.

public:
 override int GetByteCount(ReadOnlySpan<char> chars);
public override int GetByteCount (ReadOnlySpan<char> chars);
override this.GetByteCount : ReadOnlySpan<char> -> int
Public Overrides Function GetByteCount (chars As ReadOnlySpan(Of Char)) As Integer

매개 변수

chars
ReadOnlySpan<Char>

인코딩할 문자 집합이 포함된 범위입니다.

반환

Int32

지정된 문자 범위를 인코딩하여 생성된 바이트 수입니다.

설명

결과 바이트를 GetByteCount저장하는 데 필요한 GetBytes 정확한 크기를 계산하려면 . 최대 크기를 계산하려면 .를 사용합니다 GetMaxByteCount. 메서드는 일반적으로 더 GetByteCount 많은 메모리를 할당 하는 것을 허용 하지만 GetMaxByteCount 메서드는 일반적으로 더 빠르게 실행 됩니다.

적용 대상

GetByteCount(String)

지정된 String의 문자를 인코딩하여 생성된 바이트 수를 계산합니다.

public:
 override int GetByteCount(System::String ^ chars);
public override int GetByteCount (string chars);
override this.GetByteCount : string -> int
Public Overrides Function GetByteCount (chars As String) As Integer

매개 변수

chars
String

인코딩할 문자 집합이 포함된 String입니다.

반환

Int32

지정한 문자를 인코딩할 경우 생성되는 바이트 수입니다.

예외

chars이(가) null인 경우

결과 바이트 수가 정수로 반환될 수 있는 최대 수보다 큽니다.

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

예제

다음 예제에서는 메서드를 사용하여 GetByteCount 문자열 ASCIIEncoding을 인코딩하는 데 필요한 바이트 수를 반환하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
int main()
{
   String^ chars = "ASCII Encoding Example";
   ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
   int byteCount = ascii->GetByteCount( chars );
   Console::WriteLine( " {0} bytes needed to encode string.", byteCount );
}
using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        String chars = "ASCII Encoding Example";

        ASCIIEncoding ascii = new ASCIIEncoding();
        int byteCount = ascii.GetByteCount(chars);
        Console.WriteLine(
            "{0} bytes needed to encode string.", byteCount
        );
    }
}
Imports System.Text

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim chars As String = "ASCII Encoding Example"

        Dim ascii As New ASCIIEncoding()
        Dim byteCount As Integer = ascii.GetByteCount(chars)
        Console.WriteLine("{0} bytes needed to encode string.", byteCount)
    End Sub
End Class

설명

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

추가 정보

적용 대상

GetByteCount(Char*, Int32)

중요

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

CLS 대체 규격
System.Text.ASCIIEncoding.GetByteCount(Char[], Int32, Int32)

지정한 문자 포인터에서 시작되는 문자 집합을 인코딩할 경우 생성되는 바이트 수를 계산합니다.

public:
 override int GetByteCount(char* chars, int count);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public override int GetByteCount (char* chars, int count);
[System.CLSCompliant(false)]
public override int GetByteCount (char* chars, int count);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (char* chars, int count);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (char* chars, int count);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int

매개 변수

chars
Char*

인코딩할 첫 번째 문자를 가리키는 포인터입니다.

count
Int32

인코딩할 문자 수입니다.

반환

Int32

지정한 문자를 인코딩할 경우 생성되는 바이트 수입니다.

특성

예외

chars이(가) null인 경우

count가 0보다 작은 경우

또는 결과 바이트 수가 정수로 반환될 수 있는 최대 수보다 큽니다.

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

설명

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

추가 정보

적용 대상

GetByteCount(Char[], Int32, Int32)

지정한 문자 배열의 문자 집합을 인코딩할 경우 생성되는 바이트 수를 계산합니다.

public:
 override int GetByteCount(cli::array <char> ^ chars, int index, int count);
public override int GetByteCount (char[] chars, int index, int count);
override this.GetByteCount : char[] * int * int -> int
Public Overrides Function GetByteCount (chars As Char(), index As Integer, count As Integer) As Integer

매개 변수

chars
Char[]

인코딩할 문자 집합이 포함된 문자 배열입니다.

index
Int32

인코딩할 첫 번째 문자의 인덱스입니다.

count
Int32

인코딩할 문자 수입니다.

반환

Int32

지정한 문자를 인코딩할 경우 생성되는 바이트 수입니다.

예외

chars이(가) null인 경우

index 또는 count가 0보다 작습니다.

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

또는 결과 바이트 수가 정수로 반환될 수 있는 최대 수보다 큽니다.

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

예제

다음 예제에서는 메서드를 사용하여 GetByteCount 유니코드 문자 ASCIIEncoding배열을 인코딩하는 데 필요한 바이트 수를 반환하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
int main()
{
   
   // Unicode characters.
   
   // Pi
   // Sigma
   array<Char>^chars = {L'\u03a0',L'\u03a3',L'\u03a6',L'\u03a9'};
   ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
   int byteCount = ascii->GetByteCount( chars, 1, 2 );
   Console::WriteLine( " {0} bytes needed to encode characters.", byteCount.ToString() );
}
using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        // Unicode characters.
        Char[] chars = new Char[] {
            '\u0023', // #
            '\u0025', // %
            '\u03a0', // Pi
            '\u03a3'  // Sigma
        };

        ASCIIEncoding ascii = new ASCIIEncoding();
        int byteCount = ascii.GetByteCount(chars, 1, 2);
        Console.WriteLine(
            "{0} bytes needed to encode characters.", byteCount
        );
    }
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings

Class ASCIIEncodingExample
    Public Shared Sub Main()
        ' Unicode characters.
        ' ChrW(35)  = #
        ' ChrW(37)  = %
        ' ChrW(928) = Pi
        ' ChrW(931) = Sigma
        Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(928), ChrW(931)}

        Dim ascii As New ASCIIEncoding()
        Dim byteCount As Integer = ascii.GetByteCount(chars, 1, 2)
        Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
    End Sub
End Class

설명

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

추가 정보

적용 대상