String extension method which checks whether the input string contains a true-like value. - CSharp System

CSharp examples for System:String Contain

Description

String extension method which checks whether the input string contains a true-like value.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*from  w ww .j  a va  2 s.  c  om*/

public class Main{
        /// <summary>
        /// String extension method which checks whether the input string contains a true-like value.
        /// </summary>
        /// <param name="input">The string on which the method is invoked.</param>
        /// <returns>Returns whether the string contains true-like value.</returns>
        public static bool ToBoolean(this string input)
        {
            var stringTrueValues = new[] { "true", "ok", "yes", "1", "??" };
            return stringTrueValues.Contains(input.ToLower());
        }
}

Related Tutorials