diff --git a/src/ServiceStack.Text/StringExtensions.cs b/src/ServiceStack.Text/StringExtensions.cs index 0e871312f..0fe09f9a6 100644 --- a/src/ServiceStack.Text/StringExtensions.cs +++ b/src/ServiceStack.Text/StringExtensions.cs @@ -918,6 +918,15 @@ public static bool ContainsAny(this string text, params string[] testMatches) return false; } + public static bool ContainsAny(this string text, StringComparison comparisonType, params string[] testMatches) + { + foreach (var testMatch in testMatches) + { + if (text.IndexOf(testMatch, comparisonType) >= 0) return true; + } + return false; + } + public static bool IsValidVarName(this string name) => InvalidVarCharsRegex.IsMatch(name); public static string SafeVarName(this string text) => !string.IsNullOrEmpty(text) diff --git a/tests/ServiceStack.Text.Tests/StringExtensionsTests.cs b/tests/ServiceStack.Text.Tests/StringExtensionsTests.cs index 6981e2227..3f9127faf 100644 --- a/tests/ServiceStack.Text.Tests/StringExtensionsTests.cs +++ b/tests/ServiceStack.Text.Tests/StringExtensionsTests.cs @@ -344,5 +344,14 @@ public void Can_convert_ToPascalCase() Assert.That("Aa_Bb".ToPascalCase(), Is.EqualTo("AaBb")); Assert.That("AA_BB".ToPascalCase(), Is.EqualTo("AaBb")); } + + [Test] + public void Does_ContainsAny_Return_CaseInsensitive_Matches() + { + var testMatches = new string[] { "abc" }; + var input = "ABC"; + + Assert.That(input.ContainsAny(StringComparison.OrdinalIgnoreCase, testMatches)); + } } }