Decoder.GetCharCount 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當在派生類別中覆寫時,會計算解碼一串位元組所產生的字元數。
多載
| 名稱 | Description |
|---|---|
| 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
- 來源:
- 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,解碼器會在資料區塊末尾的尾隨位元組儲存在內部緩衝區,並在下一次解碼操作中使用這些位元組。 應用程式應在呼叫GetCharCount同一區塊前立即呼叫GetChars該資料區塊,使得前一個區塊的尾隨位元組被納入計算中。
適用於
GetCharCount(Byte*, Int32, Boolean)
- 來源:
- Decoder.cs
- 來源:
- Decoder.cs
- 來源:
- 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
傳回
解碼指定位元組序列及內部緩衝區中任意位元組所產生的字元數。
- 屬性
例外狀況
bytes 是 null(在Visual Basic .NET中為 Nothing)。
count 小於零。
備註
此方法不影響解碼器的狀態。
為了計算儲存所得字元所需的精確陣列大小 GetChars ,應用程式應使用 GetCharCount。
若 GetChars 被呼叫,且將 flush 設為 false,解碼器會在資料區塊末尾的尾隨位元組儲存在內部緩衝區,並在下一次解碼操作中使用這些位元組。 應用程式應在呼叫GetCharCount同一區塊前立即呼叫GetChars該資料區塊,使得前一個區塊的尾隨位元組被納入計算中。
另請參閱
適用於
GetCharCount(Byte[], Int32, Int32)
- 來源:
- Decoder.cs
- 來源:
- Decoder.cs
- 來源:
- 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
需要解碼的位元組數。
傳回
解碼指定位元組序列及內部緩衝區中任意位元組所產生的字元數。
例外狀況
bytes 是 null (Nothing)。
範例
以下程式碼範例示範如何使用此 GetCharCount 方法計算解碼陣列中指定位元組範圍所需的字元數。
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,解碼器會在資料區塊末尾的尾隨位元組儲存在內部緩衝區,並在下一次解碼操作中使用這些位元組。 應用程式應在呼叫GetCharCount同一區塊前立即呼叫GetChars該資料區塊,使得前一個區塊的尾隨位元組被納入計算中。
另請參閱
適用於
GetCharCount(Byte[], Int32, Int32, Boolean)
- 來源:
- Decoder.cs
- 來源:
- Decoder.cs
- 來源:
- 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
傳回
解碼指定位元組序列及內部緩衝區中任意位元組所產生的字元數。
- 屬性
例外狀況
bytes 是 null (Nothing)。
備註
此方法不影響解碼器的狀態。
為了計算儲存所得字元所需的精確陣列大小 GetChars ,應用程式應使用 GetCharCount。
若 GetChars 被呼叫,且將 flush 設為 false,解碼器會在資料區塊末尾的尾隨位元組儲存在內部緩衝區,並在下一次解碼操作中使用這些位元組。 應用程式應在呼叫GetCharCount同一區塊前立即呼叫GetChars該資料區塊,使得前一個區塊的尾隨位元組被納入計算中。