CompareInfo Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Implements a set of methods for culture-sensitive string comparisons.
Assembly: mscorlib (in mscorlib.dll)
The CompareInfo type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Compare(String, String) | Compares two strings and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Compare(String, String, CompareOptions) | Compares two strings using the specified CompareOptions value and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Compare(String, Int32, String, Int32) | Compares the end section of a string with the end section of another string and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Compare(String, Int32, String, Int32, CompareOptions) | Compares the end section of a string with the end section of another string using the specified CompareOptions value and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Compare(String, Int32, Int32, String, Int32, Int32) | Compares a section of one string with a section of another string and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Compare(String, Int32, Int32, String, Int32, Int32, CompareOptions) | Compares a section of one string with a section of another string using the specified CompareOptions value and returns an integer that indicates their relationship to one another in the sort order. |
![]() | Equals | Determines whether the specified object is equal to the current CompareInfo object. (Overrides Object::Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetCompareInfo | Initializes a new CompareInfo object that is associated with the culture with the specified name. |
![]() | GetHashCode | Serves as a hash function for the current CompareInfo for hashing algorithms and data structures, such as a hash table. (Overrides Object::GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IndexOf(String, Char) | Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string. |
![]() | IndexOf(String, String) | Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string. |
![]() | IndexOf(String, Char, CompareOptions) | Searches for the specified character and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value. |
![]() | IndexOf(String, String, CompareOptions) | Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string using the specified CompareOptions value. |
![]() | IndexOf(String, Char, Int32, CompareOptions) | Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value. |
![]() | IndexOf(String, Char, Int32, Int32) | Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements. |
![]() | IndexOf(String, String, Int32, CompareOptions) | Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value. |
![]() | IndexOf(String, String, Int32, Int32) | Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements. |
![]() | IndexOf(String, Char, Int32, Int32, CompareOptions) | Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value. |
![]() | IndexOf(String, String, Int32, Int32, CompareOptions) | Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified CompareOptions value. |
![]() | IsPrefix(String, String) | Determines whether the specified source string starts with the specified prefix. |
![]() | IsPrefix(String, String, CompareOptions) | Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value. |
![]() | IsSuffix(String, String) | Determines whether the specified source string ends with the specified suffix. |
![]() | IsSuffix(String, String, CompareOptions) | Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value. |
![]() | LastIndexOf(String, Char) | Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string. |
![]() | LastIndexOf(String, String) | Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string. |
![]() | LastIndexOf(String, Char, CompareOptions) | Searches for the specified character and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value. |
![]() | LastIndexOf(String, String, CompareOptions) | Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string using the specified CompareOptions value. |
![]() | LastIndexOf(String, Char, Int32, CompareOptions) | Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value. |
![]() | LastIndexOf(String, Char, Int32, Int32) | Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index. |
![]() | LastIndexOf(String, String, Int32, CompareOptions) | Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that extends from the beginning of the string to the specified index using the specified CompareOptions value. |
![]() | LastIndexOf(String, String, Int32, Int32) | Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index. |
![]() | LastIndexOf(String, Char, Int32, Int32, CompareOptions) | Searches for the specified character and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value. |
![]() | LastIndexOf(String, String, Int32, Int32, CompareOptions) | Searches for the specified substring and returns the zero-based index of the last occurrence within the section of the source string that contains the specified number of elements and ends at the specified index using the specified CompareOptions value. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current CompareInfo. (Overrides Object::ToString().) |
The CultureInfo class includes a CompareInfo property that returns an instance of this class. Some string comparison methods, such as String::Compare, use the information in a CultureInfo::CompareInfo object to compare strings.
The CompareInfo class provides the GetCompareInfo method, instead of public constructors, to allow for late-bound access.
To create a CompareInfo object for any culture, the application should use the CultureInfo::CompareInfo property, or use the CompareInfo::GetCompareInfo method and provide the name of the culture whose CompareInfo object is to be returned.
Ignored Search Values
Comparison operations, such as those performed by the IndexOf or LastIndexOf methods, can yield unexpected results if the value to search for is ignored. The search value is ignored under the following conditions:
It is an empty string ("").
It consists of characters whose code points are not considered in the operation because of comparison options. For example, this occurs if the search string includes symbols and the value passed to a parameter of type CompareOptions includes the CompareOptions::IgnoreSymbols flag.
It consists of characters whose code points have no linguistic significance.
If the search value for the IndexOf method is an empty string, for example, the return value is zero.
Security Considerations
If a security decision depends on a string comparison, the application should test for equality using ordinal comparison. It should not use the Compare method.
Version Notes
Windows Phone
String comparison operations for strings containing trigraphs may not work as expected for cultures where trigraphs are used, such as "dzh" in the culture hu-HU. For example, IndexOf(String, String, CompareOptions) and IsSuffix(String, String, CompareOptions) may return an incorrect result.The following example shows how the CompareInfo object associated with a CultureInfo object affects string comparison.



