Convert.ToByte (Char) converts Unicode character to 8-bit unsigned integer.
Class Sample
Public Shared Sub Main()
Dim chars() As Char = { "a"c, "z"c, ChrW(7), ChrW(1023) }
For Each ch As Char in chars
Try
Dim result As Byte = Convert.ToByte(ch)
Console.WriteLine("{0} is converted to {1}.", ch, result)
Catch e As OverflowException
Console.WriteLIne("Unable to convert u+{0} to a byte.", _
AscW(ch).ToString("X4"))
End Try
Next
End Sub
End Class
Related examples in the same category