中匹配案例不敏感的字符串
c#的內置方法對大小寫。 要執行不敏感的底帶檢查,您需要採取不同的方法。 Contains()
方法提供了使用IndexOf()
選項的解決方案:StringComparison.OrdinalIgnoreCase
>
string title = "STRING"; bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0;
public static class StringExtensions { public static bool ContainsIgnoreCase(this string source, string toCheck) { return source?.IndexOf(toCheck, StringComparison.OrdinalIgnoreCase) >= 0; } }
string title = "STRING"; bool contains = title.ContainsIgnoreCase("string");
以上是我如何執行不敏感的字符串包含C#中的檢查?的詳細內容。更多資訊請關注PHP中文網其他相關文章!