Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

contains with ignore case c#

/*
OrdinalIgnoreCase compares the character codes without cultural aspects. 
This is good for exact comparisons, like login names, but not for sorting 
strings with unusual characters like é or ö. This is also faster because there
are no extra rules to apply before comparing.
*/
  
string FirstString = "I love my country!";
string SecondString = "Love";
bool result = FirstString.Contains(SecondString, StringComparison.OrdinalIgnoreCase);
Console.WriteLine(result);

/*
InvariantCultureIgnoreCase uses comparison rules based on english, but without
any regional variations. This is good for a neutral comparison that still takes
into account some linguistic aspects.
*/
string FirstString = "I love my country!";
string SecondString = "Love";
bool result = FirstString.Contains(SecondString, StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine(result);
 
PREVIOUS NEXT
Tagged: #ignore #case
ADD COMMENT
Topic
Name
2+5 =