ASCIIEncoding.GetCharCount メソッド

定義

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

オーバーロード

GetCharCount(Byte*, Int32)

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

GetCharCount(Byte[], Int32, Int32)

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

GetCharCount(ReadOnlySpan<Byte>)

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

GetCharCount(Byte*, Int32)

Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs

重要

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

CLS 準拠の代替
System.Text.ASCIIEncoding.GetCharCount(Byte[], Int32, Int32)

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

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

count が 0 未満です。

または

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

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

および

DecoderFallbackDecoderExceptionFallback に設定されます。

注釈

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

こちらもご覧ください

適用対象

GetCharCount(Byte[], Int32, Int32)

Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs

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

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

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

または

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

または

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

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

および

DecoderFallbackDecoderExceptionFallback に設定されます。

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

using namespace System;
using namespace System::Text;
int main()
{
   array<Byte>^bytes = {65,83,67,73,73,32,69,110,99,111,100,105,110,103,32,69,120,97,109,112,108,101};
   ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
   int charCount = ascii->GetCharCount( bytes, 6, 8 );
   Console::WriteLine( "{0} characters needed to decode bytes.", charCount );
}
using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {
             65,  83,  67,  73,  73,  32,  69,
            110,  99, 111, 100, 105, 110, 103,
             32,  69, 120,  97, 109, 112, 108, 101
        };

        ASCIIEncoding ascii = new ASCIIEncoding();
        int charCount = ascii.GetCharCount(bytes, 6, 8);
        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
        );
    }
}
Imports System.Text

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim bytes() As Byte = { _
             65,  83,  67,  73,  73,  32,  69, _
            110,  99, 111, 100, 105, 110, 103, _
             32,  69, 120,  97, 109, 112, 108, 101}
      
        Dim ascii As New ASCIIEncoding()
        Dim charCount As Integer = ascii.GetCharCount(bytes, 6, 8)
        Console.WriteLine("{0} characters needed to decode bytes.", charCount)
    End Sub
End Class

注釈

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

こちらもご覧ください

適用対象

GetCharCount(ReadOnlySpan<Byte>)

Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs
Source:
ASCIIEncoding.cs

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

public:
 override int GetCharCount(ReadOnlySpan<System::Byte> bytes);
public override int GetCharCount (ReadOnlySpan<byte> bytes);
override this.GetCharCount : ReadOnlySpan<byte> -> int
Public Overrides Function GetCharCount (bytes As ReadOnlySpan(Of Byte)) As Integer

パラメーター

bytes
ReadOnlySpan<Byte>

デコードするバイトのセットを格納しているスパン。

戻り値

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

注釈

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

適用対象