Convert.ToChar (String) converts the first character of a string to a Unicode character.
Class Sample
Public Shared Sub Main()
Dim nullString As String = Nothing
Dim strings() As String = { "A", "This", vbTab, nullString }
Dim result As Char
For Each strng As String In strings
Try
result = Convert.ToChar(strng)
Console.WriteLine("'{0}' converts to '{1}'.", strng, result)
Catch e As FormatException
Console.WriteLine("'{0}' is not in the correct format for conversion to a Char.", _
strng)
Catch e As ArgumentNullException
Console.WriteLine("A null string cannot be converted to a Char.")
End Try
Next
End Sub
End Class
Related examples in the same category