ASCIIEncoding.GetCharCount Metod

Definition

Beräknar antalet tecken som genereras genom avkodning av en sekvens med byte.

Överlagringar

Name Description
GetCharCount(Byte[], Int32, Int32)

Beräknar antalet tecken som genereras genom avkodning av en sekvens med byte från den angivna bytematrisen.

GetCharCount(Byte*, Int32)

Beräknar antalet tecken som genereras genom avkodning av en sekvens med byte som börjar vid den angivna bytepekaren.

GetCharCount(Byte[], Int32, Int32)

Beräknar antalet tecken som genereras genom avkodning av en sekvens med byte från den angivna bytematrisen.

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

Parametrar

bytes
Byte[]

Bytematrisen som innehåller sekvensen med byte som ska avkodas.

index
Int32

Indexet för den första byte som ska avkodas.

count
Int32

Antalet byte som ska avkodas.

Returer

Antalet tecken som genereras genom avkodning av den angivna sekvensen med byte.

Undantag

bytes är null.

index eller count är mindre än noll.

-eller-

index och count ange inte ett giltigt intervall i bytes.

-eller-

Det resulterande antalet byte är större än det maximala antalet som kan returneras som ett heltal.

En reserv inträffade (mer information finns i Character Encoding i .NET)

-och-

DecoderFallback är inställt på DecoderExceptionFallback.

Exempel

I följande exempel visas hur du använder GetCharCount metoden för att returnera antalet tecken som genereras genom avkodning av ett område med element i en bytematris.

using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {
             65,  83,  67,  73,  73,  32,  69,
            110,  99, 111, 100, 105, 110, 103,
             32,  69, 120,  97, 109, 112, 108, 101
        };

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

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim bytes() As Byte = { _
             65,  83,  67,  73,  73,  32,  69, _
            110,  99, 111, 100, 105, 110, 103, _
             32,  69, 120,  97, 109, 112, 108, 101}
      
        Dim ascii As New ASCIIEncoding()
        Dim charCount As Integer = ascii.GetCharCount(bytes, 6, 8)
        Console.WriteLine("{0} characters needed to decode bytes.", charCount)
    End Sub
End Class

Kommentarer

För att beräkna den exakta matrisstorlek som krävs för GetChars att lagra de resulterande tecknen använder GetCharCountprogrammet . För att beräkna den maximala matrisstorleken bör programmet använda GetMaxCharCount. Metoden GetCharCount tillåter vanligtvis allokering av mindre minne, medan GetMaxCharCount metoden vanligtvis körs snabbare.

Se även

Gäller för

GetCharCount(Byte*, Int32)

Viktigt!

Detta API uppfyller inte CLS.

Alternativ som uppfyller CLS
System.Text.ASCIIEncoding.GetCharCount(Byte[], Int32, Int32)

Beräknar antalet tecken som genereras genom avkodning av en sekvens med byte som börjar vid den angivna bytepekaren.

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)]
[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)]
public override int GetCharCount(byte* bytes, int count);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
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
[<System.CLSCompliant(false)>]
override this.GetCharCount : nativeptr<byte> * int -> int

Parametrar

bytes
Byte*

En pekare till den första byte som ska avkodas.

count
Int32

Antalet byte som ska avkodas.

Returer

Antalet tecken som genereras genom avkodning av den angivna sekvensen med byte.

Attribut

Undantag

bytes är null.

count är mindre än noll.

-eller-

Det resulterande antalet byte är större än det maximala antalet som kan returneras som ett heltal.

En reserv inträffade (mer information finns i Character Encoding i .NET)

-och-

DecoderFallback är inställt på DecoderExceptionFallback.

Kommentarer

För att beräkna den exakta matrisstorlek som krävs för GetChars att lagra de resulterande tecknen använder GetCharCountprogrammet . För att beräkna den maximala matrisstorleken bör programmet använda GetMaxCharCount. Metoden GetCharCount tillåter vanligtvis allokering av mindre minne, medan GetMaxCharCount metoden vanligtvis körs snabbare.

Se även

Gäller för