次の方法で共有


UTF7Encoding.GetCharCount メソッド (Byte , Int32, Int32)

バイト配列の指定した範囲の要素をデコードした結果、取得される文字数を計算します。

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 および countbytes 内の有効な範囲を示していません。

解説

デコードされたバイトを格納するために GetChars メソッドによって要求された配列サイズを正確に計算するには GetCharCount を使用し、その最大値を計算するには GetMaxCharCount を使用します。

使用例

[Visual Basic, C#, C++] UTF7Encoding を使用してバイト配列 bytes からある範囲の要素をデコードし、その結果の文字数を GetCharCount メソッドを使用して返す方法を次の例に示します。

 
Imports System
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 'Main
End Class 'UnicodeEncodingExample

[C#] 
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
        );
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;

int main()
{
   Byte bytes[] =  {
      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(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

参照

UTF7Encoding クラス | UTF7Encoding メンバ | System.Text 名前空間 | UTF7Encoding.GetCharCount オーバーロードの一覧