String efficient methods for things like “case insensitive contains”.

public static bool StartsWithAndContains(this string toSearch, string startsWith, string contains)
 {
 return toSearch.StartsWithIgnoreCase(startsWith) && toSearch.ContainsIgnoreCase(contains);
 }public static bool EqualsIgnoreCase(this string toSearch, string equals)
 {
 return string.Equals(toSearch, equals, StringComparison.OrdinalIgnoreCase);
 }

public static bool StartsWithIgnoreCase(this string toSearch, string startsWith)
 {
 return toSearch.StartsWith(startsWith, StringComparison.OrdinalIgnoreCase);
 }

public static bool ContainsIgnoreCase(this string toSearch, string contains)
 {
 return (contains == string.Empty || toSearch.IndexOf(contains, StringComparison.OrdinalIgnoreCase) != -1);
 }
Share on Facebook

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>