This documentation is archived and is not being maintained.

ASCIIEncoding.GetCharCount Method

Calculates the number of characters that would result from decoding a set of elements in a byte array.

Overload List

Calculates the number of characters that would result from decoding a specified range of elements in a byte array.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Overrides Public Function GetCharCount(Byte(), Integer, Integer) As Integer
[C#] public override int GetCharCount(byte[], int, int);
[C++] public: int GetCharCount(unsigned char __gc[], int, int);
[JScript] public override function GetCharCount(Byte[], int, int) : int;

Inherited from Encoding.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function GetCharCount(Byte()) As Integer
[C#] public virtual int GetCharCount(byte[]);
[C++] public: virtual int GetCharCount(unsigned char __gc[]);
[JScript] public function GetCharCount(Byte[]) : int;

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the GetCharCount method to return the number of characters that result from decoding a range of elements in a byte array.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetCharCount. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
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

[C#] 
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
        );
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;

int main()
{
   Byte bytes[] =  
   {
      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(S"{0} characters needed to decode bytes.", __box(charCount));
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ASCIIEncoding Class | ASCIIEncoding Members | System.Text Namespace

Show: