Encoding.GetCharCount calculates the number of characters produced by decoding : Encoding « Internationalization I18N « VB.Net






Encoding.GetCharCount calculates the number of characters produced by decoding

 

Imports System
Imports System.Text
Imports Microsoft.VisualBasic

Public Class SamplesEncoding   
   Public Shared Sub Main()
      Dim u32LE As Encoding = Encoding.GetEncoding("utf-32")
      Dim u32BE As Encoding = Encoding.GetEncoding("utf-32BE")

      Dim myStr As String = "za" & ChrW(&H0306) & ChrW(&H01FD) & ChrW(&H03B2) 

      Dim barrBE(u32BE.GetByteCount(myStr) - 1) As Byte
      u32BE.GetBytes(myStr, 0, myStr.Length, barrBE, 0)

      Dim barrLE(u32LE.GetByteCount(myStr) - 1) As Byte
      u32LE.GetBytes(myStr, 0, myStr.Length, barrLE, 0)

      PrintCountsAndChars(barrBE, u32BE)
      PrintCountsAndChars(barrLE, u32LE)
   End Sub 'Main
   Public Shared Sub PrintCountsAndChars(bytes() As Byte, enc As Encoding)
      Console.Write("{0,-25} :", enc.ToString())
      Dim iCC As Integer = enc.GetCharCount(bytes)
      Console.Write(" {0,-3}", iCC)
      Dim iMCC As Integer = enc.GetMaxCharCount(bytes.Length)
      Console.Write(" {0,-3} :", iMCC)
      Dim chars As Char() = enc.GetChars(bytes)
      Console.WriteLine(chars)
   End Sub 
End Class

   
  








Related examples in the same category

1.Convert the string into a byte[]
2.Perform the conversion from one encoding to the other.
3.Encoder Class converts a set of characters into a sequence of bytes.
4.Encode characters
5.Encode characters using an Encoder object
6.Encoder Constructor initializes a new instance of the Encoder class.
7.Encoder.GetByteCount
8.Encoder.GetBytes
9.Encoding Class represents a character encoding.
10.Perform the conversion from one encoding to the other
11.Encoding\Encoding.ASCII Property gets an encoding for the ASCII (7-bit) character set.
12.Encoding.BigEndianUnicode Property gets an encoding for the UTF-16 format that uses the big endian byte order.
13.Read a text file saved with Big Endian Unicode encoding
14.Encoding.UTF7
15.Encoding.Unicode
16.Encoding.BigEndianUnicode
17.Encoding.UTF32
18.Encoding.BodyName
19.Encoding.Equals determines whether the specified Object is equal to the current instance.
20.Encoding.GetByteCount (Char[]) calculates the number of bytes
21.Encoding.GetByteCount calculates the number of bytes
22.Encoding.GetEncodings returns an array that contains all encodings.
23.Encoding.GetPreamble returns a sequence of bytes that specifies the encoding used.
24.Calculates the number of bytes produced by encoding a set of characters from the specified character array.
25.Calculates the number of bytes produced by encoding the characters in the specified String.
26.Encodes a set of characters from the specified character array into the specified byte array.
27.Encodes a set of characters from the specified String into the specified byte array.
28.Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
29.Decodes a sequence of bytes from the specified byte array into the specified character array.
30.Returns the hash code for the current instance.
31.Calculates the maximum number of bytes produced by encoding the specified number of characters.
32.Calculates the maximum number of characters produced by decoding the specified number of bytes.
33.Returns a Unicode byte order mark encoded in UTF-16 format
34.UTF7Encoding Class represents a UTF-7 encoding of Unicode characters.
35.Whether to provide a Unicode byte order mark and whether to throw an exception
36.Calculates number of bytes produced by encoding a set of characters from the specified character array.
37.Calculates the number of bytes produced by encoding the characters in the specified String.
38.Encodes a set of characters from the specified character array into the specified byte array.
39.Encodes a set of characters from the specified String into the specified byte array.
40.Get an encoding for code page 1252 (Western Europe character set)
41.UTF-16 encoding of Unicode characters.
42.Represents a UTF-32 encoding of Unicode characters.
43.Represents a UTF-8 encoding of Unicode characters.