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) です。

結果のバイト数が、int として返すことのできる最大数を超えています。

フォールバックが発生しました (詳細については、「 .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 未満です。

  • または - 結果のバイト数が、int として返すことのできる最大数を超えています。

フォールバックが発生しました (詳細については「.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 未満です。

または index および countcharsにおいて有効な範囲を表していません。

  • または - 結果のバイト数が、int として返すことのできる最大数を超えています。

フォールバックが発生しました (詳細については「.NET での文字エンコード」を参照) および EncoderFallbackEncoderExceptionFallback に設定されます。

次のコード例は、このメソッドを使用 GetByteCount して、Unicode 文字の配列をエンコードするために必要なバイト数を返す方法を示しています。

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 メソッドは通常、より高速に実行されます。

こちらもご覧ください

適用対象