Encoder.GetBytes
Imports System
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class EncoderExample
Public Shared Sub Main()
Dim bytes() As Byte
' ChrW(928) = Pi ChrW(931) = Sigma
Dim chars() As Char = {ChrW(928), ChrW(931)}
Dim uniEncoder As Encoder = Encoding.Unicode.GetEncoder()
Dim byteCount As Integer = uniEncoder.GetByteCount(chars, 0, chars.Length, True)
bytes = New Byte(byteCount - 1) {}
Dim bytesEncodedCount As Integer = uniEncoder.GetBytes(chars, 0, chars.Length, bytes, 0, True)
Console.WriteLine(bytesEncodedCount)
Dim b As Byte
For Each b In bytes
Console.Write("[{0}]", b)
Next b
End Sub
End Class
Related examples in the same category