You would think there would be a way using DirectCast, TryCast, CType etc but all of them seem to choke on it e.g.:
CType(\"Yes\", Boolean)
No, but you could do something like:
bool yes = "Yes".Equals(yourString);
public static bool IsBoolean(string strValue)
{
return !string.IsNullOrEmpty(strValue) && ("1/YES/TRUE".IndexOf(strValue, StringComparison.CurrentCultureIgnoreCase) >= 0);
}
private bool StrToBool(string value)
{ // could be yes/no, Yes/No, true/false, True/False, 1/0
bool b = false;
if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals(Boolean.TrueString, StringComparison.CurrentCultureIgnoreCase) || value.Equals("1"))
{
b = true;
}
else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase) || value.Equals(Boolean.FalseString, StringComparison.CurrentCultureIgnoreCase) || value.Equals("0"))
{
b = false;
}
else
{ // we should't be here
b = false;
}
return b;
}
Here is a simple way to get this done.
rv.Complete = If(reader("Complete") = "Yes", True, False)
You Can't. But you should use it as
bool result = yourstring.ToLower() == "yes";
Public Function TrueFalseToYesNo(thisValue As Boolean) As String
Try
If thisValue Then
Return "Yes"
Else
Return "No"
End If
Catch ex As Exception
Return thisValue.ToString
End Try
End Function