Mega Code Archive

 
Categories / VB.Net Tutorial / Development
 

GetChars method decodes a range of elements in a byte array and store the result in a character array

Imports System Imports System.Text Class MainClass     Public Shared Sub Main()         Dim chars() As Char         Dim bytes() As Byte = {5, 0, 10, 0, 5, 0, 99, 0, 1, 0, 1, 0, 101, 0}         Dim uni As New UnicodeEncoding()         Dim charCount As Integer = uni.GetCharCount(bytes, 2, 8)         chars = New Char(charCount - 1) {}         Dim charsDecodedCount As Integer = uni.GetChars(bytes, 2, 8, chars, 0)         Console.WriteLine("{0} characters used to decode bytes.", charsDecodedCount)         Console.Write("Decoded chars: ")         Dim c As Char         For Each c In  chars             Console.Write("[{0}]", c)         Next c     End Sub End Class