Export (0) Print
Expand All

UnicodeEncoding.GetCharCount Method

Calculates the number of characters that would result from decoding the 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 would result from decoding a range of elements in the byte array bytes using a UnicodeEncoding.

[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 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 'Main
End Class 'UnicodeEncodingExample

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

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

int main()
{
   Byte bytes[] =  {
      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(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

UnicodeEncoding Class | UnicodeEncoding Members | System.Text Namespace

Show:
© 2014 Microsoft