Is there any way to search patterns in strings in C#?
Something like Sql LIKE would be very useful.
public static bool Like(this string value, string pattern)
{
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(pattern))
return false;
bool valid = true;
string[] words = pattern.Split("*");
int counter = words.Count();
for (int i = 0; i < counter; i++)
{
valid = valid && value.StartsWith(words[i]);
value = value.Substring(words[i].Length);
}
return valid;
}