Performing Case-Insensitive String Comparison

To perform case-insensitive comparison of strings, set the ordering strength of the ICollation object to ignore the level of difference represented by a case difference. Generally cases represent a tertiary difference, although this may differ between languages. This means you set the collation object to consider only primary and secondary differences and ignore tertiary differences.

  1. Create the collation object by calling ICollation::createCollation, specifying the desired locale and ordering strength (ICollation::kSecondaryDifference).
  2. Call the compare function or one of the helper functions isEqual, isGreaterThan, or isLessThan to compare the two strings.

For example, this code shows how to do case-insensitive comparison of two strings, text1 and text2, using the collation object for U.S. English:

// Create a locale key for the U.S. English locale

ILocaleKey usLoc("EN", "US");

// Create the collation object

ICollation* order = ICollation::createCollation(usLoc, 

			ICollation::kSecondaryDifference);

int result = order->compare(text1, text2);

if (result == ICollation::kSourceEqual)

	// strings are equal or only have case differences

else

	// strings are not equal

delete order;


Overview of Locale Classes
Locale Names
Collation Classes
Ordering Strength