Sitecore 5.0 API

MainUtil.GetBool Method (String, Boolean)

Gets the boolean value of a string.

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

Parameters

s
A string.
_default
A default boolean value.

Return Value

The boolean value of the string.

Remarks

The boolean value is true, if the string is one of the following values (case-insensitive):

Otherwise the value is false.

The default value is returned if the string is blank or null.

Example

  bool b0 = MainUtil.BoolToString("true", false); // true
  bool b1 = MainUtil.BoolToString("True", false); // true
  bool b2 = MainUtil.BoolToString("yes", false); // true
  bool b3 = MainUtil.BoolToString("1", false); // true
  bool b4 = MainUtil.BoolToString("no", false); // false
  bool b5 = MainUtil.BoolToString("false", false); // false
  bool b6 = MainUtil.BoolToString("", false); // false
  bool b6 = MainUtil.BoolToString("", true); // true
  bool b6 = MainUtil.BoolToString(null, true); // true

See Also

MainUtil Class | Sitecore Namespace | MainUtil.GetBool Overload List