Decoder.GetCharCount 方法

定义

在派生类中重写时,计算对字节序列进行解码所产生的字符数。

重载

GetCharCount(ReadOnlySpan<Byte>, Boolean)

在派生类中重写时,计算对范围中字节序列进行解码所产生的字符数。 一个参数,该参数指示是否在计算后清除解码器的内部状态。

GetCharCount(Byte*, Int32, Boolean)

在派生类中重写时,计算对字节序列(从指定的字节指针开始)进行解码所产生的字符数。 一个参数,该参数指示是否在计算后清除解码器的内部状态。

GetCharCount(Byte[], Int32, Int32)

在派生类中重写时,计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。

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

在派生类中重写时,计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。 一个参数,该参数指示是否在计算后清除解码器的内部状态。

GetCharCount(ReadOnlySpan<Byte>, Boolean)

在派生类中重写时,计算对范围中字节序列进行解码所产生的字符数。 一个参数,该参数指示是否在计算后清除解码器的内部状态。

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

返回

Int32

对指定的字节序列和内部缓冲区中任何字节进行解码所产生的字符数。

注解

此方法不影响解码器的状态。

若要计算存储生成的字符所需的确切缓冲区大小, GetChars 应用程序应使用 GetCharCount

如果在设置为 时调用 ,则解码器将尾随字节存储在内部缓冲区中数据块末尾,并用于下一个 GetChars flush false 解码操作。 应用程序应在对同一块调用 之前立即对数据块调用 ,以便计算中包含上一块的任何 GetCharCount GetChars 尾随字节。

适用于

GetCharCount(Byte*, Int32, Boolean)

重要

此 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);
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
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

返回

Int32

对指定的字节序列和内部缓冲区中任何字节进行解码所产生的字符数。

属性

例外

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

count 小于零。

发生回退(有关详细信息,请参阅采用 .NET 的字符编码

-和-

Fallback 设置为 DecoderExceptionFallback

注解

此方法不影响解码器的状态。

若要计算存储生成的字符所需的确切数组大小, GetChars 应用程序应使用 GetCharCount

如果在设置为 时调用 ,则解码器将尾随字节存储在内部缓冲区中数据块末尾,并用于下一个 GetChars flush false 解码操作。 应用程序应在对同一块调用 之前立即对数据块调用 ,以便计算中包含上一块的任何 GetCharCount GetChars 尾随字节。

另请参阅

适用于

GetCharCount(Byte[], Int32, Int32)

在派生类中重写时,计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。

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

要解码的字节数。

返回

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 解码操作。 应用程序应在对同一块调用 之前立即对数据块调用 ,以便计算中包含上一块的任何 GetCharCount GetChars 尾随字节。

另请参阅

适用于

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

在派生类中重写时,计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。 一个参数,该参数指示是否在计算后清除解码器的内部状态。

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

返回

Int32

对指定的字节序列和内部缓冲区中任何字节进行解码所产生的字符数。

属性

例外

bytesnull (Nothing)。

indexcount 小于零。

  • 或 -

indexcount 不表示 bytes 中的有效范围。

发生回退(有关详细信息,请参阅采用 .NET 的字符编码

-和-

Fallback 设置为 DecoderExceptionFallback

注解

此方法不影响解码器的状态。

若要计算存储生成的字符所需的确切数组大小, GetChars 应用程序应使用 GetCharCount

如果在设置为 时调用 ,则解码器将尾随字节存储在内部缓冲区中数据块末尾,并用于下一个 GetChars flush false 解码操作。 应用程序应在对同一块调用 之前立即对数据块调用 ,以便计算中包含上一块的任何 GetCharCount GetChars 尾随字节。

另请参阅

适用于