Επεξεργασία

Κοινή χρήση μέσω


CompareInfo Class

Definition

Implements a set of methods for culture-sensitive string comparisons.

public ref class CompareInfo
public ref class CompareInfo sealed : System::Runtime::Serialization::IDeserializationCallback
public ref class CompareInfo : System::Runtime::Serialization::IDeserializationCallback
public class CompareInfo
public sealed class CompareInfo : System.Runtime.Serialization.IDeserializationCallback
public class CompareInfo : System.Runtime.Serialization.IDeserializationCallback
[System.Serializable]
public class CompareInfo : System.Runtime.Serialization.IDeserializationCallback
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CompareInfo : System.Runtime.Serialization.IDeserializationCallback
type CompareInfo = class
type CompareInfo = class
    interface IDeserializationCallback
[<System.Serializable>]
type CompareInfo = class
    interface IDeserializationCallback
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CompareInfo = class
    interface IDeserializationCallback
Public Class CompareInfo
Public NotInheritable Class CompareInfo
Implements IDeserializationCallback
Public Class CompareInfo
Implements IDeserializationCallback
Inheritance
CompareInfo
Attributes
Implements

Examples

The following example shows how the CompareInfo object associated with a CultureInfo object affects string comparison.

using namespace System;
using namespace System::Text;
using namespace System::Globalization;

int main()
{
    array<String^>^ sign = gcnew array<String^> { "<", "=", ">" };

    // The code below demonstrates how strings compare
    // differently for different cultures.
    String^ s1 = "Coté"; 
    String^ s2 = "coté";
    String^ s3 = "côte";

    // Set sort order of strings for French in France.
    CompareInfo^ ci = (gcnew CultureInfo("fr-FR"))->CompareInfo;
    Console::WriteLine(L"The LCID for {0} is {1}.", ci->Name, ci->LCID);

    // Display the result using fr-FR Compare of Coté = coté.
    Console::WriteLine(L"fr-FR Compare: {0} {2} {1}",
        s1, s2, sign[ci->Compare(s1, s2, CompareOptions::IgnoreCase) + 1]);

    // Display the result using fr-FR Compare of coté > côte.
    Console::WriteLine(L"fr-FR Compare: {0} {2} {1}",
        s2, s3, sign[ci->Compare(s2, s3, CompareOptions::None) + 1]);

    // Set sort order of strings for Japanese as spoken in Japan.
    ci = (gcnew CultureInfo("ja-JP"))->CompareInfo;
    Console::WriteLine(L"The LCID for {0} is {1}.", ci->Name, ci->LCID);

    // Display the result using ja-JP Compare of coté < côte.
    Console::WriteLine("ja-JP Compare: {0} {2} {1}",
        s2, s3, sign[ci->Compare(s2, s3) + 1]);
}

// This code produces the following output.
//
// The LCID for fr-FR is 1036.
// fr-FR Compare: Coté = coté
// fr-FR Compare: coté > côte
// The LCID for ja-JP is 1041.
// ja-JP Compare: coté < côte
using System;
using System.Text;
using System.Globalization;

public sealed class App
{
    static void Main(string[] args)
    {
        String[] sign = new String[] { "<", "=", ">" };

        // The code below demonstrates how strings compare
        // differently for different cultures.
        String s1 = "Coté", s2 = "coté", s3 = "côte";

        // Set sort order of strings for French in France.
        CompareInfo ci = new CultureInfo("fr-FR").CompareInfo;
        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

        // Display the result using fr-FR Compare of Coté = coté.  	
        Console.WriteLine("fr-FR Compare: {0} {2} {1}",
            s1, s2, sign[ci.Compare(s1, s2, CompareOptions.IgnoreCase) + 1]);

        // Display the result using fr-FR Compare of coté > côte.
        Console.WriteLine("fr-FR Compare: {0} {2} {1}",
            s2, s3, sign[ci.Compare(s2, s3, CompareOptions.None) + 1]);

        // Set sort order of strings for Japanese as spoken in Japan.
        ci = new CultureInfo("ja-JP").CompareInfo;
        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

        // Display the result using ja-JP Compare of coté < côte.
        Console.WriteLine("ja-JP Compare: {0} {2} {1}",
            s2, s3, sign[ci.Compare(s2, s3) + 1]);
    }
}

// This code produces the following output.
//
// The LCID for fr-FR is 1036.
// fr-FR Compare: Coté = coté
// fr-FR Compare: coté > côte
// The LCID for ja-JP is 1041.
// ja-JP Compare: coté < côte
Imports System.Text
Imports System.Globalization

NotInheritable Public Class App
    Shared Sub Main(ByVal args() As String) 
        Dim sign() As String = {"<", "=", ">"}
        
        ' The code below demonstrates how strings compare 
        ' differently for different cultures.
        Dim s1 As String = "Coté"
        Dim s2 As String = "coté"
        Dim s3 As String = "côte"
        
        ' Set sort order of strings for French in France.
        Dim ci As CompareInfo = New CultureInfo("fr-FR").CompareInfo
        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID)
        
        ' Display the result using fr-FR Compare of Coté = coté.  	
        Console.WriteLine("fr-FR Compare: {0} {2} {1}", _
                          s1, s2, sign((ci.Compare(s1, s2, CompareOptions.IgnoreCase) + 1)))
        
        ' Display the result using fr-FR Compare of coté > côte.
        Console.WriteLine("fr-FR Compare: {0} {2} {1}", _
                          s2, s3, sign((ci.Compare(s2, s3, CompareOptions.None) + 1)))
        
        ' Set sort order of strings for Japanese as spoken in Japan.
        ci = New CultureInfo("ja-JP").CompareInfo
        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID)
        
        ' Display the result using ja-JP Compare of coté < côte. 
        Console.WriteLine("ja-JP Compare: {0} {2} {1}", _
                          s2, s3, sign((ci.Compare(s2, s3) + 1)))
    End Sub
End Class

' This code produces the following output.
' 
' The LCID for fr-FR is 1036.
' fr-FR Compare: Coté = coté
' fr-FR Compare: coté > côte
' The LCID for ja-JP is 1041.
' ja-JP Compare: coté < côte

Remarks

For more information about this API, see Supplemental API remarks for CompareInfo.

Properties

LCID

Gets the properly formed culture identifier for the current CompareInfo.

Name

Gets the name of the culture used for sorting operations by this CompareInfo object.

Version

Gets information about the version of Unicode used for comparing and sorting strings.

Methods

Compare(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Compares two read-only spans of characters.

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.

Compare(String, Int32, Int32, String, Int32, Int32)

Compares a section of one string with a section of another string.

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.

Compare(String, Int32, String, Int32)

Compares the end section of a string with the end section of another string.

Compare(String, String, CompareOptions)

Compares two strings using the specified CompareOptions value.

Compare(String, String)

Compares two strings.

Equals(Object)

Determines whether the specified object is equal to the current CompareInfo object.

GetCompareInfo(Int32, Assembly)

Initializes a new CompareInfo object that is associated with the specified culture and that uses string comparison methods in the specified Assembly.

GetCompareInfo(Int32)

Initializes a new CompareInfo object that is associated with the culture with the specified identifier.

GetCompareInfo(String, Assembly)

Initializes a new CompareInfo object that is associated with the specified culture and that uses string comparison methods in the specified Assembly.

GetCompareInfo(String)

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.

GetHashCode(ReadOnlySpan<Char>, CompareOptions)

Gets the hash code for a character span based on specified comparison options.

GetHashCode(String, CompareOptions)

Gets the hash code for a string based on specified comparison options.

GetSortKey(ReadOnlySpan<Char>, Span<Byte>, CompareOptions)

Computes a sort key for the specified input.

GetSortKey(String, CompareOptions)

Gets a SortKey object for the specified string using the specified CompareOptions value.

GetSortKey(String)

Gets the sort key for the specified string.

GetSortKeyLength(ReadOnlySpan<Char>, CompareOptions)

Gets the total number of sort key bytes that would be produced from the specified input.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Searches for the first occurrence of a substring within a source string.

IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Searches for the first occurrence of a substring within the specified read-only span of characters.

IndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

Searches for the first occurrence of a Rune within the specified read-only span of characters.

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, 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, 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, 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, Char, Int32)

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.

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, 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, 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, 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.

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, String, Int32)

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.

IndexOf(String, String)

Searches for the specified substring and returns the zero-based index of the first occurrence within the entire source string.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Determines whether a string starts with a specific prefix.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Determines whether a read-only span of characters starts with a specific prefix.

IsPrefix(String, String, CompareOptions)

Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value.

IsPrefix(String, String)

Determines whether the specified source string starts with the specified prefix.

IsSortable(Char)

Indicates whether a specified Unicode character is sortable.

IsSortable(ReadOnlySpan<Char>)

Indicates whether a specified Unicode read-only span of characters is sortable.

IsSortable(Rune)

Indicates whether a specified Rune is sortable.

IsSortable(String)

Indicates whether a specified Unicode string is sortable.

IsSuffix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Determines whether a string ends with a specific suffix.

IsSuffix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Determines whether a read-only span of characters ends with a specific suffix.

IsSuffix(String, String, CompareOptions)

Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.

IsSuffix(String, String)

Determines whether the specified source string ends with the specified suffix.

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Searches for the last occurrence of a substring within a source string.

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Searches for the last occurrence of a substring within the specified read-only span of characters.

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

Searches for the last occurrence of a Rune within the specified read-only span of characters.

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, 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, 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, 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, Char, Int32)

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.

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, 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, 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, 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.

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, String, Int32)

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.

LastIndexOf(String, String)

Searches for the specified substring and returns the zero-based index of the last occurrence within the entire source string.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current CompareInfo object.

Explicit Interface Implementations

IDeserializationCallback.OnDeserialization(Object)

Runs when the entire object graph has been deserialized.

Extension Methods

GetStringComparer(CompareInfo, CompareOptions)

Returns a StringComparer object based on the culture-sensitive string comparison rules of a specified CompareInfo object.

Applies to

See also