UTF7Encoding.GetCharCount Método

Definição

Calcula o número de caracteres produzidos pela decodificação de uma sequência de bytes.Calculates the number of characters produced by decoding a sequence of bytes.

Sobrecargas

GetCharCount(Byte[], Int32, Int32)

Calcula o número de caracteres produzidos pela decodificação de uma sequência de bytes da matriz de bytes especificada.Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

GetCharCount(Byte*, Int32)

Calcula o número de caracteres produzidos pela decodificação de uma sequência de bytes começando no ponteiro de bytes especificado.Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.

GetCharCount(Byte[], Int32, Int32)

Calcula o número de caracteres produzidos pela decodificação de uma sequência de bytes da matriz de bytes especificada.Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

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

Parâmetros

bytes
Byte[]

A matriz de bytes que contém a sequência de bytes a ser decodificada.The byte array containing the sequence of bytes to decode.

index
Int32

O índice do primeiro byte a ser decodificado.The index of the first byte to decode.

count
Int32

O número de bytes a serem decodificados.The number of bytes to decode.

Retornos

Int32

O número de caracteres produzido pela decodificação da sequência de bytes especificada.The number of characters produced by decoding the specified sequence of bytes.

Exceções

bytes é null (Nothing).bytes is null (Nothing).

index ou count é menor que zero.index or count is less than zero.

- ou --or- index e count não denotam um intervalo válido em bytes.index and count do not denote a valid range in bytes.

- ou --or- Número excessivo de caracteres. O número de caracteres resultante é maior que o número máximo que pode ser retornado como um int.The resulting number of characters is greater than the maximum number that can be returned as an int.

Ocorreu um fallback (saiba mais em Codificação de caracteres no .NET)A fallback occurred (for more information, see Character Encoding in .NET) -e--and- DecoderFallback é definido como DecoderExceptionFallback.DecoderFallback is set to DecoderExceptionFallback.

Exemplos

O exemplo de código a seguir demonstra como usar o GetCharCount método para retornar o número de caracteres produzidos pela decodificação de um intervalo de elementos em uma matriz de bytes.The following code example demonstrates how to use the GetCharCount method to return the number of characters produced by decoding a range of elements in a byte 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};
   UnicodeEncoding^ Unicode = gcnew UnicodeEncoding;
   int charCount = Unicode->GetCharCount( bytes, 2, 8 );
   Console::WriteLine( "{0} characters needed to decode bytes.", charCount );
}

using System;
using System.Text;

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

        UnicodeEncoding Unicode = new UnicodeEncoding();
        int charCount = Unicode.GetCharCount(bytes, 2, 8);
        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
        );
    }
}
Imports System.Text

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        Dim bytes() As Byte = {85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0}
        
        Dim uni As New UnicodeEncoding()
        Dim charCount As Integer = uni.GetCharCount(bytes, 2, 8)
        Console.WriteLine("{0} characters needed to decode bytes.", charCount)
    End Sub
End Class

Comentários

Para calcular o tamanho exato da matriz exigido pelo GetChars para armazenar os caracteres resultantes, use GetCharCount .To calculate the exact array size required by GetChars to store the resulting characters, use GetCharCount. Para calcular o tamanho máximo da matriz, o aplicativo deve usar GetMaxCharCount .To calculate the maximum array size, the application should use GetMaxCharCount. O GetCharCount método geralmente permite a alocação de menos memória, enquanto o GetMaxCharCount método geralmente é executado mais rapidamente.The GetCharCount method generally allows allocation of less memory, while the GetMaxCharCount method generally executes faster.

Confira também

Aplica-se a

GetCharCount(Byte*, Int32)

Importante

Esta API não está em conformidade com CLS.

Calcula o número de caracteres produzidos pela decodificação de uma sequência de bytes começando no ponteiro de bytes especificado.Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.

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

Parâmetros

bytes
Byte*

Um ponteiro do primeiro byte a ser decodificado.A pointer to the first byte to decode.

count
Int32

O número de bytes a serem decodificados.The number of bytes to decode.

Retornos

Int32

O número de caracteres produzido pela decodificação da sequência de bytes especificada.The number of characters produced by decoding the specified sequence of bytes.

Atributos

Exceções

bytes é null (Nothing).bytes is null (Nothing).

count é menor que zero.count is less than zero.

- ou --or- Número excessivo de caracteres. O número de caracteres resultante é maior que o número máximo que pode ser retornado como um int.The resulting number of characters is greater than the maximum number that can be returned as an int.

Ocorreu um fallback (confira Codificação de caracteres no .NET para obter uma explicação mais completa).A fallback occurred (see Character Encoding in .NET for fuller explanation).

-e--and- DecoderFallback é definido como DecoderExceptionFallback.DecoderFallback is set to DecoderExceptionFallback.

Comentários

Para calcular o tamanho exato da matriz exigido pelo GetChars para armazenar os caracteres resultantes, use GetCharCount .To calculate the exact array size required by GetChars to store the resulting characters, use GetCharCount. Para calcular o tamanho máximo da matriz, o aplicativo deve usar GetMaxCharCount .To calculate the maximum array size, the application should use GetMaxCharCount. O GetCharCount método geralmente permite a alocação de menos memória, enquanto o GetMaxCharCount método geralmente é executado mais rapidamente.The GetCharCount method generally allows allocation of less memory, while the GetMaxCharCount method generally executes faster.

Confira também

Aplica-se a