Checks if the string is bool true/false value. - CSharp System

CSharp examples for System:String Parse

Description

Checks if the string is bool true/false value.

Demo Code

/*//from w  w w .jav a2s.c  o  m
 * $Id: StringUtils.cs 465 2008-10-15 11:53:17Z spocke $
 *
 * Copyright ? 2007, Moxiecode Systems AB, All rights reserved. 
 */
using System.Text.RegularExpressions;
using System.Text;
using System;

public class Main{
        /// <summary>
		///  Checks if the string is bool true/false value.
		/// </summary>
		/// <param name="str">String to check.</param>
		/// <returns>true/false depending on string contents.</returns>
		public static bool CheckBool(string str) {
			if (str == null)
				return false;

 			str = str.Trim().ToLower();

			return str == "yes" || str == "true" || str == "1";
		}
}

Related Tutorials