Performs a case-insensitive comparison and returns true if the string is contained within the current string. - CSharp System

CSharp examples for System:String Case

Description

Performs a case-insensitive comparison and returns true if the string is contained within the current string.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Generic;
using System;// www .j a va2 s. c o  m

public class Main{
        /// <summary>
        /// Performs a case-insensitive comparison and returns true if the string is contained within the current string.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="compare"></param>
        /// <returns></returns>
        public static bool CaseInsensitiveContains(this string self, params string[] compare)
        {
            foreach (var t in compare)
            {
                if (self == null && t == null) return true;
                if (self == null || t == null) return false;

                if (self.ToLowerInvariant().Contains(t.ToLowerInvariant())) return true;
            }
            return false;
        }
}

Related Tutorials