UTF7Encoding.GetByteCount 메서드

정의

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

오버로드

GetByteCount(String)

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

GetByteCount(Char*, Int32)

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

GetByteCount(Char[], Int32, Int32)

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

GetByteCount(String)

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

public:
 override int GetByteCount(System::String ^ s);
public override int GetByteCount (string s);
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (string s);
override this.GetByteCount : string -> int
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : string -> int
Public Overrides Function GetByteCount (s As String) As Integer

매개 변수

s
String

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

반환

Int32

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

특성

예외

snull(Nothing)입니다.

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

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

EncoderFallbackEncoderExceptionFallback로 설정됩니다.

예제

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

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

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

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

Class UTF7EncodingExample
    
    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 utf7 As New UTF7Encoding()
        Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
        Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
    End Sub
End Class

설명

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

추가 정보

적용 대상

GetByteCount(Char*, Int32)

중요

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

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

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

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

특성

예외

charsnull(Visual Basic .NET의 경우 Nothing)입니다.

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

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

예외

charsnull(Nothing)입니다.

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

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

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

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

예제

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

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

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

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

Class UTF7EncodingExample
    
    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 utf7 As New UTF7Encoding()
        Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
        Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
    End Sub
End Class

설명

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

추가 정보

적용 대상