Convert.ToBoolean Method (String)

Converts the specified string representation of a logical value to its Boolean equivalent.

Namespace:  System
Assemblies:   System.Runtime.Extensions (in System.Runtime.Extensions.dll)
  mscorlib (in mscorlib.dll)

Public Shared Function ToBoolean ( _
	value As String _
) As Boolean


Type: System.String

A string that contains the value of either Boolean.TrueString or Boolean.FalseString.

Return Value

Type: System.Boolean
true if value equals TrueString, or false if value equals FalseString or Nothing.


value is not equal to TrueString or FalseString.

For a successful conversion to occur, the value parameter must equal either Boolean.TrueString, a constant whose value is True, Boolean.FalseString, a constant whose value is False, or it must be Nothing. In comparing value with Boolean.TrueString and Boolean.FalseString, the method ignores case as well as leading and trailing white space.

If you prefer not to handle an exception if the conversion fails, you can call the Boolean.TryParse method instead. It returns a Boolean value that indicates whether the conversion succeeded or failed.

The following example uses the Convert.ToBoolean(String) method to convert various strings to Boolean values.

Module BooleanConversion
   Public Sub Main()
      Dim values() As String = { Nothing, String.Empty, "true", 
                                 "TrueString", "False", "    false    ",
                                 "-1", "0" }
      For Each value In values                                 
            Console.WriteLine("Converted '{0}' to {1}.", value, _ 
         Catch e As FormatException
            Console.WriteLine("Unable to convert '{0}' to a Boolean.", value)
         End Try 
   End Sub 
End Module 
' The example displays the following output to the console: 
'       Converted '' to False. 
'       Unable to convert '' to a Boolean. 
'       Converted 'true' to True. 
'       Unable to convert 'TrueString' to a Boolean. 
'       Converted 'False' to False. 
'       Converted '    false    ' to False. 
'       Unable to convert '-1' to a Boolean. 
'       Unable to convert '0' to a Boolean.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft