バイト配列の指定した範囲の要素をデコードした結果、取得される文字数を計算します。
Overrides Overloads Public Function GetCharCount( _
ByVal bytes() As Byte, _ ByVal index As Integer, _ ByVal count As Integer _) As Integer
[C#]
public override int GetCharCount(byte[] bytes,intindex,intcount);
[C++]
public: int GetCharCount(unsigned charbytes __gc[],intindex,intcount);
[JScript]
public override function GetCharCount(
bytes : Byte[],index : int,count : int) : int;
パラメータ
- bytes
デコードするバイト配列。 - index
デコードする bytes 内の最初のバイトのインデックス。 - count
デコードするバイト数。
戻り値
bytes 内の指定した範囲の要素をデコードした結果、取得される可能性がある文字数。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | bytes が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | index または count が 0 未満です。
または index に count を加算した値が、 bytes の長さを超えています。 |
解説
デコードされたバイトを格納するために GetChars メソッドによって要求された配列サイズを、正確に計算するには GetCharCount を使用し、最大値を計算するには GetMaxCharCount を使用します。
使用例
[Visual Basic, C#, C++] バイト配列からある範囲の要素をデコードし、その結果の文字数を GetCharCount メソッドを使用して返す方法を次の例に示します。
Imports System
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
[C#]
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
);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;
int main()
{
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 = new ASCIIEncoding();
int charCount = ascii -> GetCharCount(bytes, 6, 8);
Console::WriteLine(S"{0} characters needed to decode bytes.", __box(charCount));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
ASCIIEncoding クラス | ASCIIEncoding メンバ | System.Text 名前空間 | ASCIIEncoding.GetCharCount オーバーロードの一覧