Encode Unicode characters array and store the encoded bytes in a byte array. : UniCode « Development « VB.Net Tutorial






Imports System
Imports System.Text
Imports Microsoft.VisualBasic.Strings

Class MainClass

    Public Shared Sub Main()
        Dim bytes() As Byte

        Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(38), ChrW(928), ChrW(931)}

        Dim uni As New UnicodeEncoding()

        Dim byteCount As Integer = uni.GetByteCount(chars, 1, 2)
        bytes = New Byte(byteCount - 1) {}
        Dim bytesEncodedCount As Integer = uni.GetBytes(chars, 1, 2, bytes, 0)

        Console.WriteLine(bytesEncodedCount)

        Dim b As Byte
        For Each b In  bytes
            Console.WriteLine(b)
        Next b
    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.