ASCIIEncoding.GetCharCount 方法

定義

計算將位元組序列解碼所產生的字元數。

多載

GetCharCount(Byte*, Int32)

計算將起始於指定位元組指標的位元組序列解碼所產生的字元數。

GetCharCount(Byte[], Int32, Int32)

計算將指定位元組陣列中的位元組序列解碼所產生的字元數。

GetCharCount(ReadOnlySpan<Byte>)

計算解碼指定位元組範圍所產生的字元數目。

GetCharCount(Byte*, Int32)

來源:
ASCIIEncoding.cs
來源:
ASCIIEncoding.cs
來源:
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 小於零。

-或-

所產生的位元組數目大於可用整數傳回的數目上限。

發生後援 (如需詳細資訊,請參閱 .NET 中的字元編碼)

-和-

DecoderFallback 設定為 DecoderExceptionFallback

備註

若要計算儲存所產生字元所需的 GetChars 確切陣列大小,應用程式會使用 GetCharCount 。 若要計算陣列大小上限,應用程式應該使用 GetMaxCharCount 。 方法 GetCharCount 通常允許配置較少的記憶體,而 GetMaxCharCount 方法通常會執行得更快。

另請參閱

適用於

GetCharCount(Byte[], Int32, Int32)

來源:
ASCIIEncoding.cs
來源:
ASCIIEncoding.cs
來源:
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

indexcount 小於零。

-或-

indexcount 不代表 bytes 中有效的範圍。

-或-

所產生的位元組數目大於可用整數傳回的數目上限。

發生後援 (如需詳細資訊,請參閱 .NET 中的字元編碼)

-和-

DecoderFallback 設定為 DecoderExceptionFallback

範例

下列範例示範如何使用 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>)

來源:
ASCIIEncoding.cs
來源:
ASCIIEncoding.cs
來源:
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 方法通常會執行得更快。

適用於