Convert.ToBoolean (String) converts string to Boolean equivalent.
Module BooleanConversion
Public Sub Main()
ConvertToBoolean(String.Empty)
ConvertToBoolean("true")
ConvertToBoolean("TrueString")
ConvertToBoolean("False")
ConvertToBoolean(" false ")
ConvertToBoolean("-1")
ConvertToBoolean("0")
End Sub
Private Sub ConvertToBoolean(value As String)
Try
Console.WriteLine("Converted '{0}' to {1}.", value,Convert.ToBoolean(value))
Catch e As FormatException
Console.WriteLine("Unable to convert '{0}' to a Boolean.", value)
End Try
End Sub
End Module
Related examples in the same category