c# - Cas insensible 39;Contenus(chaînes)

Mots clés : c#stringcontainscase-insensitivec#

meilleur 5 Réponses c# - Cas insensible 39;Contenus(chaînes)

vote vote

92

string title = "STRING"; bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0; 
public static class StringExtensions {     public static bool Contains(this string source, string toCheck, StringComparison comp)     {         return source?.IndexOf(toCheck, comp) >= 0;     } } 
if (source == null) return false; return source.IndexOf(toCheck, comp) >= 0; 
string title = "STRING"; bool contains = title.Contains("string", StringComparison.OrdinalIgnoreCase); 
vote vote

87

culture.CompareInfo.IndexOf(paragraph, word, CompareOptions.IgnoreCase) >= 0 
vote vote

73

string title = "STRING";  if (title.IndexOf("string", 0, StringComparison.CurrentCultureIgnoreCase) != -1) {     // The string exists in the original } 
vote vote

65

bool contains = Regex.IsMatch("StRiNG to search", Regex.Escape("string"), RegexOptions.IgnoreCase); 
vote vote

54

"Test".Contains("test", System.StringComparison.CurrentCultureIgnoreCase); 

Questions similaires