New Sberry Sberry wants ‘Delineate’ to be not equal to DELINEATE which is again not equal to dElINeate and sort them based on their case and culture. How to do…?

Here comes the StringComparision enum which we can pass to the comparison, equal functions of string to make the sorting and comparison based on the culture-specific sort rules and comparison rules.

Formal Lines
The StringComparison enumeration is used to specify whether a string comparison should use the current culture or the invariant culture, word or ordinal sort rules, and be case-sensitive or case-insensitive.

StringComparision Enumeration has the following member

1. CurrentCulture
2. CurrentCultureIgnoreCase
3. InvariantCulture
4. InvariantCultureIgnoreCase
5. Ordinal
6. OrdinalIgnoreCase

An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each char in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy.

Example:
string.Compare(s.FromAssetCode.ToLower().Trim(),
fixedAssetDM.Code.ToLower().Trim(),StringComparison.Ordinal) <= 0

Happy Learning 🙂

Advertisements