Persisting linguistically meaningful but culturally-agnostic data.īased on these rules you should use: string title = "STRING" Operations in most cases one of the few exceptions would be Use StringComparison.InvariantCulture -based string.Or implicitly specify the string comparison mechanism. Use overloads for string operations that don't explicitly.Use ToUpperInvariant rather than ToLowerInvariant when.Linguistically irrelevant (symbolic, for example). Switch current use of string operations based on the invariantĬulture to use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase when the comparison is.Use StringComparison.CurrentCulture-based string operations.Use StringComparison.OrdinalIgnoreCase comparisons.Use StringComparison.OrdinalIgnoreCase for comparisonsĪs your safe default for culture-agnostic string matching.Since this is missing, here are some recommendations about when to use which one: Dos OrdinalIgnoreCase, CurrentCultureIgnoreCase or InvariantCultureIgnoreCase? Given English's hegemony in software, you should probably resort to CultureInfo.InvariantCulture, because it will be wrong in familiar ways. If you don't know, you'll have to take a punt. To summarise, you can only answer the question 'are these two strings the same but in different cases' if you know what language the text is in.
(Turks, please correct me if I'm wrong, or suggest a better example) As I understand, one means 'spirit' and the other is an onomatopoeia word. Thus the strings tin and TIN are the same word in English, but different words in Turkish. The Turkish upper case version of 'i' is the unfamiliar character 'İ'. For example, the English language uses the characters I and i for the upper and lower case versions of the ninth letter, whereas the Turkish language uses these characters for the eleventh and twelfth letters of its 29 letter-long alphabet.
This solution is transparent about the definition of case-insensitivity, which is language dependent. Where culture is the instance of CultureInfo describing the language that the text is written in. To test if the string paragraph contains the string word (thanks (paragraph, word, CompareOptions.IgnoreCase) >= 0