Decode a range of elements from a byte array and store them in a Unicode character array. : UniCode « Development « VB.Net Tutorial






Imports System
Imports System.Text

Class MainClass

    Public Shared Sub Main()
        Dim chars() As Char
        Dim bytes() As Byte = {5, 0, 10, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0}

        Dim uniDecoder As Decoder = Encoding.Unicode.GetDecoder()

        Dim charCount As Integer = uniDecoder.GetCharCount(bytes, 0, bytes.Length)
        chars = New Char(charCount - 1) {}
        Dim charsDecodedCount As Integer = uniDecoder.GetChars(bytes, 0, bytes.Length, chars, 0)

        Console.WriteLine(charsDecodedCount)

        Dim c As Char
        For Each c In  chars
            Console.Write("[{0}]", c)
        Next c
    End Sub
End Class








7.29.UniCode
7.29.1.UI with UniCodeUI with UniCode
7.29.2.Decode a range of elements from a byte array and store them in a Unicode character array.
7.29.3.Use the GetByteCount to get the number of bytes required to encode an array of Unicode characters, using UTF8Encoding.
7.29.4.Encode Unicode characters array and store the encoded bytes in a byte array.