From 33faec9649ad47f64ea47af55925e8e3f85006d3 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 17:21:03 -0500 Subject: [PATCH] ContainsNoCase Extension for Contains() used extensively, here as `ContainsNoCase` for indexOf() with StringComparison type options: CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase The extension here implements the String.IndexOf Method (String,StringComparison) method: https://msdn.microsoft.com/en-us/library/ms224425(v=vs.110).aspx Allows clean access to this method as `ContainsNoCase(string, StringComparison.TYPE)` --- src/NadekoBot/_Extensions/Extensions.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 8dbdf02b..f95e6fbb 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -278,6 +278,15 @@ namespace NadekoBot.Extensions return list; } } + + /// + /// Easy use of fast, efficient case-insensitive Contains check with StringComparison Member Types + /// CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase + /// + public static bool ContainsNoCase(this string str, string contains, StringComparison compare) + { + return str.IndexOf(contains, compare) >= 0; + } public static string TrimTo(this string str, int maxLength, bool hideDots = false) { @@ -436,4 +445,4 @@ namespace NadekoBot.Extensions : usr.AvatarUrl; } } -} \ No newline at end of file +}