Sitecore 5.0 API

MainUtil.StringToBool Method 

Converts a string to boolean.

[Visual Basic]
Public Shared Function StringToBool( _
   ByVal _value As String, _
   ByVal _default As Boolean _
) As Boolean
[C#]
public static bool StringToBool(
   string _value,
   bool _default
);

Parameters

_value
A string.
_default
A default value.

Return Value

True, if the string is "true", false, if the string is "false", otherwise the default value.

Remarks

Only the values 'true' or 'false' are recognized. For all other values, the default will be returned. The comparison is case-insensitive.

Example

  bool b0 = MainUtil.StringToBool("True", true); // true
  bool b1 = MainUtil.StringToBool("false", true); // false
  bool b0 = MainUtil.StringToBool("", true); // true
  bool b0 = MainUtil.StringToBool("abc", false); // false
  bool b0 = MainUtil.StringToBool("yes", false); // false
  bool b0 = MainUtil.StringToBool("1", false); // false

See Also

MainUtil Class | Sitecore Namespace | BoolToString