vote buttons
6
13 Mar 2015 by Super Human

Case Insensitive String.Contains Extension Method

Contract
GlobalExtensionMethods
public static bool Contains(this string source, string toSeek, StringComparison comparisonType);
Test Cases
vote buttons
0
Created By Super Human
public void WhenStringContainsSearchedWord_ReturnsTrue() { var str = "This string contains what you seek."; Assert.IsTrue(str.Contains("SEEK", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(str.Contains("seek", StringComparison.OrdinalIgnoreCase)); }
vote buttons
0
Created By Super Human
public void WhenStringDoesNotContainsSearchedWord_ReturnsFalse() { var str = "This string contains what you seek."; Assert.IsFalse(str.Contains("other", StringComparison.OrdinalIgnoreCase)); }
vote buttons
0
Created By Super Human
using System.Globalization; public void WhenStringInTurkishLocale_ContainsSearchedWord_ReturnsTrue() { Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); var str = "This string contains an integer."; Assert.IsTrue(str.Contains("INTEGER", StringComparison.OrdinalIgnoreCase)); }
You must be logged in to add test cases

1 Solution

vote buttons
5
0.03
avg time in ms
13 Mar 2015 by Super Human
public static class GlobalExtensionMethods { public static bool Contains(this string source, string toSeek, StringComparison comparisonType) { return source.IndexOf(toSeek, comparisonType) >= 0; } }
Test Case Run Summary
WhenStringContainsSearchedWord_ReturnsTrue
WhenStringDoesNotContainsSearchedWord_ReturnsFalse
WhenStringInTurkishLocale_ContainsSearchedWord_ReturnsTrue
download solution
Try this Solution
Comments