Decoder.GetCharCount Method

Definition

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes.

Overloads

GetCharCount(ReadOnlySpan<Byte>, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding the sequence of bytes in the span. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(Byte*, Int32, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(Byte[], Int32, Int32)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

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

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(ReadOnlySpan<Byte>, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding the sequence of bytes in the span. A parameter indicates whether to clear the internal state of the decoder after the calculation.

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

Parameters

bytes
ReadOnlySpan<Byte>

A byte span to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Remarks

This method does not affect the state of the decoder.

To calculate the exact buffer size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

Applies to

GetCharCount(Byte*, Int32, Boolean)

Important

This API is not CLS-compliant.

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the decoder after the calculation.

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

Parameters

bytes
Byte*

A pointer to the first byte to decode.

count
Int32

The number of bytes to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Attributes

Exceptions

bytes is null (Nothing in Visual Basic .NET).

count is less than zero.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to

GetCharCount(Byte[], Int32, Int32)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

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

Parameters

bytes
Byte[]

The byte array containing the sequence of bytes to decode.

index
Int32

The index of the first byte to decode.

count
Int32

The number of bytes to decode.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Exceptions

bytes is null (Nothing).

index or count is less than zero.

-or-

index and count do not denote a valid range in bytes.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Examples

The following code example demonstrates how to use the GetCharCount method to calculate the number of characters required to decode the specified range of bytes in the array.

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.
'

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to

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

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. A parameter indicates whether to clear the internal state of the decoder after the calculation.

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

Parameters

bytes
Byte[]

The byte array containing the sequence of bytes to decode.

index
Int32

The index of the first byte to decode.

count
Int32

The number of bytes to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Attributes

Exceptions

bytes is null (Nothing).

index or count is less than zero.

-or-

index and count do not denote a valid range in bytes.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to