UTF7Encoding.GetCharCount メソッド

定義

バイト シーケンスをデコードすることによって生成される文字数を計算します。

オーバーロード

GetCharCount(Byte[], Int32, Int32)

指定したバイト配列からバイト シーケンスをデコードすることによって生成される文字数を計算します。

GetCharCount(Byte*, Int32)

指定したバイト ポインターで始まるバイト シーケンスをデコードすることによって生成される文字数を計算します。

GetCharCount(Byte[], Int32, Int32)

指定したバイト配列からバイト シーケンスをデコードすることによって生成される文字数を計算します。

public:
 override int GetCharCount(cli::array <System::Byte> ^ bytes, int index, int count);
public override int GetCharCount (byte[] bytes, int index, int count);
override this.GetCharCount : byte[] * int * int -> int
Public Overrides Function GetCharCount (bytes As Byte(), index As Integer, count As Integer) As Integer

パラメーター

bytes
Byte[]

デコード対象のバイト シーケンスが格納されたバイト配列。

index
Int32

デコードする最初のバイトのインデックス。

count
Int32

デコードするバイト数。

戻り値

指定したバイト シーケンスをデコードすることによって生成される文字数。

例外

bytesnull (Nothing) です。

index または count が 0 未満です。

または

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

- または -

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

フォールバックが発生しました (詳細については「.NET での文字エンコード」を参照)

および

DecoderFallbackDecoderExceptionFallback に設定されます。

次のコード例では、 メソッドを使用 GetCharCount して、バイト配列内の要素の範囲をデコードすることによって生成される文字数を返す方法を示します。

using namespace System;
using namespace System::Text;
int main()
{
   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 );
   Console::WriteLine( "{0} characters needed to decode bytes.", charCount );
}
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        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);
        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
        );
    }
}
Imports System.Text

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        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)
        Console.WriteLine("{0} characters needed to decode bytes.", charCount)
    End Sub
End Class

注釈

結果の文字を格納するために 必要な GetChars 配列サイズを正確に計算するには、 を使用 GetCharCountします。 配列の最大サイズを計算するには、アプリケーションで を使用 GetMaxCharCountする必要があります。 メソッドは一般に、より GetCharCount 少ないメモリの割り当てを可能にしますが、 GetMaxCharCount メソッドは通常、より高速に実行されます。

こちらもご覧ください

適用対象

GetCharCount(Byte*, Int32)

重要

この API は CLS 準拠ではありません。

指定したバイト ポインターで始まるバイト シーケンスをデコードすることによって生成される文字数を計算します。

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

パラメーター

bytes
Byte*

デコードする最初のバイトへのポインター。

count
Int32

デコードするバイト数。

戻り値

指定したバイト シーケンスをデコードすることによって生成される文字数。

属性

例外

bytesnull (Nothing) です。

count が 0 未満です。

- または -

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

フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)。

および

DecoderFallbackDecoderExceptionFallback に設定されます。

注釈

結果の文字を格納するために 必要な GetChars 配列サイズを正確に計算するには、 を使用 GetCharCountします。 配列の最大サイズを計算するには、アプリケーションで を使用 GetMaxCharCountする必要があります。 メソッドは一般に、より GetCharCount 少ないメモリの割り当てを可能にしますが、 GetMaxCharCount メソッドは通常、より高速に実行されます。

こちらもご覧ください

適用対象