Imports System
Imports System.Text
Imports Microsoft.VisualBasic
Class UTF8EncodingExample
Public Shared Sub Main()
Dim utf8 As New UTF8Encoding()
Dim utf8ThrowException As New UTF8Encoding(False, True)
Dim chars() As Char = {"a"c, "b"c, "c"c, ChrW(55297), ChrW(55298), "d"c}
Dim bytes As Byte() = utf8.GetBytes(chars)
ShowArray(bytes)
Try
bytes = utf8ThrowException.GetBytes(chars)
Catch e As Exception
Console.WriteLine("Exception raised. " + ControlChars.Cr + "Message: {0}", e.Message)
End Try
End Sub
Public Shared Sub ShowArray(theArray As Array)
Dim o As Object
For Each o In theArray
Console.Write("[{0}]", o)
Next o
Console.WriteLine()
End Sub
End Class