OrdinalIgnoreCase, CurrentCultureIgnoreCase or InvariantCultureIgnoreCase?
Since this is missing, here are some recommendations about when to use which one:
Dos
- Use
StringComparison.OrdinalIgnoreCase
for comparisons
as your safe default for culture-agnostic string matching.
- Use
StringComparison.OrdinalIgnoreCase
comparisons
for increased speed.
- Use
StringComparison.CurrentCulture-based
string operations
when displaying the output to the user.
- Switch current use of string operations based on the invariant
culture to use the non-linguistic
StringComparison.Ordinal
or StringComparison.OrdinalIgnoreCase
when the comparison is
linguistically irrelevant (symbolic, for example).
- Use
ToUpperInvariant
rather than ToLowerInvariant
when
normalizing strings for comparison.
Don'ts
- Use overloads for string operations that don't explicitly
or implicitly specify the string comparison mechanism.
- Use
StringComparison.InvariantCulture
-based string
operations in most cases; one of the few exceptions would be
persisting linguistically meaningful but culturally-agnostic data.
Based on these rules you should use:
string title = "STRING";
if (title.IndexOf("string", 0, StringComparison.[YourDecision]) != -1)
{
// The string exists in the original
}
whereas [YourDecision] depends on the recommendations from above.
link of source: http://msdn.microsoft.com/en-us/library/ms973919.aspx