Use scenarios
String comparison
When used in EF or elsewhere, string comparisons are very common.
Sometimes it cannot meet the needs of using conversion to uppercase or lowercase.
So using another string comparison makes a lot of sense.
Code Example
class Program { static void Main(string[] args) { CompareInfo Compare = ; string a = "AaasasaAAaasaa"; string b = "aaasasaAaaasaa"; ((a, b, ) ); (); } }
CompareOptions Supplement
CompareOptions is not only used to ignore case for string comparisons.
It can also be used to ignore symbols, spaces, etc.
It can be said to be very useful.
// // Summary: // Define the string comparison options to use. [ComVisible(true)] [Flags] public enum CompareOptions { // // Summary: // Default option settings indicating string comparison. None = 0, // // Summary: // Indicates that string comparisons must ignore case. IgnoreCase = 1, // // Summary: // Indicates that string comparisons must ignore non-space combination characters, such as label characters. Unicode Standard Defines a combined character as a character with the base to generate a new character combination. Non-space combination characters do not take up space when rendered. IgnoreNonSpace = 2, // // Summary: // Indicates that string comparisons must ignore symbols, such as whitespace characters, punctuation points, currency symbols, percentage symbols, mathematical symbols, and symbols, and so on. IgnoreSymbols = 4, // // Summary: // Indicates that the pseudonym type must be ignored by string comparison. The Kana type is referenced as Japanese hiragana and Katakana characters, indicating the pronunciation in Japanese. Hiragana is used for native Japanese expressions and words, while Katakana is used for words borrowed from other languages such as "computer" or "Internet". // Pinyin sound can be represented in Hiragana and Katakana. If this value is selected, the Hiragana character of one sound is considered an equal Katakana character of the same sound. IgnoreKanaType = 8, // // Summary: // Indicates that string comparison must ignore character width. For example, the Japanese Katakana character can be written as a full or half-width. If this value is selected, the full-width form of the Katakana character is treated as the same character written in the same half-width form. IgnoreWidth = 16, // // Summary: // String comparison must ignore case and then perform sequence number comparison. This method is equivalent to converting to uppercase using fixed culture and then performing a sequence number comparison on the result. OrdinalIgnoreCase = 268435456, // // Summary: // Indicates that string comparison must use string sorting algorithm. Sorting strings, hyphens and apostrophes, and other non-alphanumeric symbols, are placed before alphanumeric characters. StringSort = 536870912, // // Summary: // Indicates that string comparisons must use a string of continuous values encoded by Unicode utf-16 (compare code units by code units), resulting in comparison speed but not culturally distinct. String and code units // XXXX Start 16 YYYY Start before the string starting with 16, if XXXX16 is less than YYYY16. This value cannot be combined with other // Value and must be used separately. Ordinal = 1073741824 }
The above is the detailed content of C# ignoring uppercase and uppercase and lowercase string comparison. For more information about C# string comparison, please pay attention to my other related articles!