String Case insensitive contains - CSharp System

CSharp examples for System:String Case

Description

String Case insensitive contains

Demo Code


using System.Text;
using System;//from   w ww .  j a  v  a  2 s . co  m

public class Main{
        /// <summary>
        ///   <para>Case insensitive contains</para>
        /// </summary>
        /// <param name = "text">Text to check</param>
        /// <param name = "value">Value to check for</param>
        /// <param name = "comparisonType">Comparison Type</param>
        /// <returns>True if matched</returns>
        public static bool Contains(this string text, string value, StringComparison comparisonType)
        {
            if (string.IsNullOrEmpty(text)) return false;
            if (string.IsNullOrEmpty(value)) return true;

            return text.IndexOf(value, comparisonType) > -1;
        }
}

Related Tutorials