using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Unity_Studio { public static class StringExtensions { /// /// Compares the string against a given pattern. /// /// The string. /// The pattern to match, where "*" means any sequence of characters, and "?" means any single character. /// true if the string matches the given pattern; otherwise false. public static bool Like(this string str, string pattern) { return new Regex( "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$", RegexOptions.IgnoreCase | RegexOptions.Singleline ).IsMatch(str); } } }