Encode characters using an Encoder object
Imports System
Imports System.Text
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.Strings
Class EncoderTest
Public Shared Sub Main()
' ChrW(928) = Pi, ChrW(931) = Sigma
Dim chars() As Char = {ChrW(928), ChrW(931)}
' Encode characters using an Encoding object.
Dim encoding As Encoding = Encoding.UTF7
Dim encoder As Encoder = encoding.GetEncoder()
Dim allCharactersFromEncoder(encoder.GetByteCount(chars, 0, chars.Length, True) ) As Byte
encoder.GetBytes(chars, 0, chars.Length, allCharactersFromEncoder, 0, True)
ShowArray(allCharactersFromEncoder)
End Sub 'Main
Public Shared Sub ShowArray(theArray As Array)
Dim o As Object
For Each o In theArray
Console.Write("[{0}]", o)
Next o
Console.WriteLine(ControlChars.NewLine)
End Sub
End Class
Related examples in the same category