Decoder.GetCharCount 方法

定義

在衍生類別中覆寫時,計算解碼位元組序列所產生的字元數目。

多載

GetCharCount(ReadOnlySpan<Byte>, Boolean)

在衍生類別中覆寫時,計算藉由解碼範圍中位元組序列所產生的字元數。 參數,指出計算後是否要清除解碼器的內部狀態。

GetCharCount(Byte*, Int32, Boolean)

在衍生類別中覆寫時,計算從指定的位元組指標開始,解碼位元組序列所產生的字元數目。 參數,指出計算後是否要清除解碼器的內部狀態。

GetCharCount(Byte[], Int32, Int32)

在衍生類別中覆寫時,計算從指定的位元組陣列解碼位元組序列所產生的字元數目。

GetCharCount(Byte[], Int32, Int32, Boolean)

在衍生類別中覆寫時,計算從指定的位元組陣列解碼位元組序列所產生的字元數目。 參數,指出計算後是否要清除解碼器的內部狀態。

GetCharCount(ReadOnlySpan<Byte>, Boolean)

來源:
Decoder.cs
來源:
Decoder.cs
來源:
Decoder.cs

在衍生類別中覆寫時,計算藉由解碼範圍中位元組序列所產生的字元數。 參數,指出計算後是否要清除解碼器的內部狀態。

public:
 virtual int GetCharCount(ReadOnlySpan<System::Byte> bytes, bool flush);
public virtual int GetCharCount (ReadOnlySpan<byte> bytes, bool flush);
abstract member GetCharCount : ReadOnlySpan<byte> * bool -> int
override this.GetCharCount : ReadOnlySpan<byte> * bool -> int
Public Overridable Function GetCharCount (bytes As ReadOnlySpan(Of Byte), flush As Boolean) As Integer

參數

bytes
ReadOnlySpan<Byte>

要解碼的位元組範圍。

flush
Boolean

true 模擬在計算後清除編碼器的內部狀態,否則為 false

傳回

解碼指定的位元組以及內部緩衝區中任何位元組序列所產生的字元數。

備註

這個方法不會影響解碼器的狀態。

若要計算需要儲存結果字元的確切緩衝區大小 GetChars ,應用程式應該使用 GetCharCount

如果 GetChars 呼叫 時 flush 設為 false ,解碼器會將尾端位元組儲存在內部緩衝區中的資料區塊結尾,並在下一個解碼作業中使用它們。 應用程式應該在相同區塊上呼叫 GetChars 之前立即呼叫 GetCharCount 資料區塊,以便計算中包含來自上一個區塊的任何尾端位元組。

適用於

GetCharCount(Byte*, Int32, Boolean)

來源:
Decoder.cs
來源:
Decoder.cs
來源:
Decoder.cs

重要

此 API 不符合 CLS 規範。

在衍生類別中覆寫時,計算從指定的位元組指標開始,解碼位元組序列所產生的字元數目。 參數,指出計算後是否要清除解碼器的內部狀態。

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

參數

bytes
Byte*

要解碼的第一個位元組指標。

count
Int32

要解碼的位元組數。

flush
Boolean

true 模擬在計算後清除編碼器的內部狀態,否則為 false

傳回

解碼指定的位元組以及內部緩衝區中任何位元組序列所產生的字元數。

屬性

例外狀況

bytesnull (在 Visual Basic .NET 中為 Nothing)。

count 小於零。

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

-和-

Fallback 設定為 DecoderExceptionFallback

備註

這個方法不會影響解碼器的狀態。

若要計算儲存結果字元所需的確切陣列大小 GetChars ,應用程式應該使用 GetCharCount

如果 GetChars 呼叫 時 flush 設為 false ,解碼器會將尾端位元組儲存在內部緩衝區中的資料區塊結尾,並在下一個解碼作業中使用它們。 應用程式應該在相同區塊上呼叫 GetChars 之前立即呼叫 GetCharCount 資料區塊,以便計算中包含來自上一個區塊的任何尾端位元組。

另請參閱

適用於

GetCharCount(Byte[], Int32, Int32)

來源:
Decoder.cs
來源:
Decoder.cs
來源:
Decoder.cs

在衍生類別中覆寫時,計算從指定的位元組陣列解碼位元組序列所產生的字元數目。

public:
 abstract int GetCharCount(cli::array <System::Byte> ^ bytes, int index, int count);
public abstract int GetCharCount (byte[] bytes, int index, int count);
abstract member GetCharCount : byte[] * int * int -> int
Public MustOverride Function GetCharCount (bytes As Byte(), index As Integer, count As Integer) As Integer

參數

bytes
Byte[]

包含要解碼之位元組序列的位元組陣列。

index
Int32

要解碼的第一個位元組索引。

count
Int32

要解碼的位元組數。

傳回

解碼指定的位元組以及內部緩衝區中任何位元組序列所產生的字元數。

例外狀況

bytesnull (Nothing)。

indexcount 小於零。

-或-

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

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

-和-

Fallback 設定為 DecoderExceptionFallback

範例

下列程式碼範例示範如何使用 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};
   Decoder^ uniDecoder = Encoding::Unicode->GetDecoder();
   int charCount = uniDecoder->GetCharCount( bytes, 0, bytes->Length );
   Console::WriteLine( "{0} characters needed to decode bytes.", charCount );
}

/* This code example produces the following output.

7 characters needed to decode bytes.

*/
using System;
using System.Text;

class DecoderExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {
            85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0
        };

        Decoder uniDecoder = Encoding.Unicode.GetDecoder();
        int charCount = uniDecoder.GetCharCount(bytes, 0, bytes.Length);
        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
        );
    }
}

/* This code example produces the following output.

7 characters needed to decode bytes.

*/
Imports System.Text

Class DecoderExample
    
    Public Shared Sub Main()
        Dim bytes() As Byte = { _
            85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0 _
        }
        
        Dim uniDecoder As Decoder = Encoding.Unicode.GetDecoder()
        Dim charCount As Integer = uniDecoder.GetCharCount(bytes, 0, bytes.Length)
        Console.WriteLine("{0} characters needed to decode bytes.", charCount)
    End Sub
End Class

'This code example produces the following output.
'
'7 characters needed to decode bytes.
'

備註

這個方法不會影響解碼器的狀態。

若要計算儲存結果字元所需的確切陣列大小 GetChars ,應用程式應該使用 GetCharCount

如果 GetChars 呼叫 時 flush 設為 false ,解碼器會將尾端位元組儲存在內部緩衝區中的資料區塊結尾,並在下一個解碼作業中使用它們。 應用程式應該在相同區塊上呼叫 GetChars 之前立即呼叫 GetCharCount 資料區塊,以便計算中包含來自上一個區塊的任何尾端位元組。

另請參閱

適用於

GetCharCount(Byte[], Int32, Int32, Boolean)

來源:
Decoder.cs
來源:
Decoder.cs
來源:
Decoder.cs

在衍生類別中覆寫時,計算從指定的位元組陣列解碼位元組序列所產生的字元數目。 參數,指出計算後是否要清除解碼器的內部狀態。

public:
 virtual int GetCharCount(cli::array <System::Byte> ^ bytes, int index, int count, bool flush);
public virtual int GetCharCount (byte[] bytes, int index, int count, bool flush);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetCharCount (byte[] bytes, int index, int count, bool flush);
abstract member GetCharCount : byte[] * int * int * bool -> int
override this.GetCharCount : byte[] * int * int * bool -> int
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetCharCount : byte[] * int * int * bool -> int
override this.GetCharCount : byte[] * int * int * bool -> int
Public Overridable Function GetCharCount (bytes As Byte(), index As Integer, count As Integer, flush As Boolean) As Integer

參數

bytes
Byte[]

包含要解碼之位元組序列的位元組陣列。

index
Int32

要解碼的第一個位元組索引。

count
Int32

要解碼的位元組數。

flush
Boolean

true 模擬在計算後清除編碼器的內部狀態,否則為 false

傳回

解碼指定的位元組以及內部緩衝區中任何位元組序列所產生的字元數。

屬性

例外狀況

bytesnull (Nothing)。

indexcount 小於零。

-或-

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

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

-和-

Fallback 設定為 DecoderExceptionFallback

備註

這個方法不會影響解碼器的狀態。

若要計算儲存結果字元所需的確切陣列大小 GetChars ,應用程式應該使用 GetCharCount

如果 GetChars 呼叫 時 flush 設為 false ,解碼器會將尾端位元組儲存在內部緩衝區中的資料區塊結尾,並在下一個解碼作業中使用它們。 應用程式應該在相同區塊上呼叫 GetChars 之前立即呼叫 GetCharCount 資料區塊,以便計算中包含來自上一個區塊的任何尾端位元組。

另請參閱

適用於