CompareInfo 类

定义

实现用于区分区域性的字符串的一组方法。

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
继承
CompareInfo
属性
实现

示例

以下示例演示与 CompareInfoCultureInfo 对象关联的对象如何影响字符串比较。

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

注解

有关此 API 的详细信息,请参阅 CompareInfo 的补充 API 说明

属性

LCID

获取当前 CompareInfo 的格式正确的区域性标识符。

Name

获取用于通过 CompareInfo 对象执行排序操作的区域性的名称。

Version

获取用于比较和排序字符串的 Unicode 版本的相关信息。

方法

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

比较字符的两个只读范围。

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

将一个字符串的一部分与另一个字符串的一部分相比较。

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

使用指定的 CompareOptions 值将一个字符串的一部分与另一个字符串的一部分相比较。

Compare(String, Int32, String, Int32)

将一个字符串的结尾部分与另一个字符串的结尾部分相比较。

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

使用指定的 CompareOptions 值将一个字符串的结尾部分与另一个字符串的结尾部分相比较。

Compare(String, String)

比较两个字符串。

Compare(String, String, CompareOptions)

使用指定的 CompareOptions 值比较两个字符串。

Equals(Object)

确定指定的对象是否等于当前 CompareInfo 对象。

GetCompareInfo(Int32)

初始化与具有指定标识符的区域性关联的新 CompareInfo 对象。

GetCompareInfo(Int32, Assembly)

初始化一个新的 CompareInfo 对象,该对象与指定区域性关联,并使用指定 Assembly 中的字符串比较方法。

GetCompareInfo(String)

初始化与具有指定名称的区域性关联的新 CompareInfo 对象。

GetCompareInfo(String, Assembly)

初始化一个新的 CompareInfo 对象,该对象与指定区域性关联,并使用指定 Assembly 中的字符串比较方法。

GetHashCode()

用作当前 CompareInfo 的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。

GetHashCode(ReadOnlySpan<Char>, CompareOptions)

根据指定的比较选项获取字符范围的哈希代码。

GetHashCode(String, CompareOptions)

根据指定的比较选项获取字符串的哈希代码。

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

计算指定输入的排序键。

GetSortKey(String)

获取指定字符串的排序关键字。

GetSortKey(String, CompareOptions)

使用指定的 SortKey 值获取指定字符串的 CompareOptions 对象。

GetSortKeyLength(ReadOnlySpan<Char>, CompareOptions)

获取将从指定输入生成的排序关键字字节的总数。

GetType()

获取当前实例的 Type

(继承自 Object)
IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

在指定字符只读范围内搜索 substring 的第一个匹配项。

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

在源字符串中搜索首次出现的子字符串。

IndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

在指定字符只读范围内搜索 Rune 的第一个匹配项。

IndexOf(String, Char)

搜索指定的字符并返回整个源字符串内第一个匹配项的从零开始的索引。

IndexOf(String, Char, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回整个源字符串内第一个匹配项的从零开始的索引。

IndexOf(String, Char, Int32)

搜索指定的字符,并返回源字符串内从指定的索引位置到字符串结尾这一部分中第一个匹配项的从零开始的索引。

IndexOf(String, Char, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回源字符串中从指定的索引位置到字符串结尾这一部分中第一个匹配项的从零开始的索引。

IndexOf(String, Char, Int32, Int32)

搜索指定的字符,并返回源字符串内从指定的索引位置开始、包含指定的元素数的部分中第一个匹配项的从零开始的索引。

IndexOf(String, Char, Int32, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回源字符串内从指定的索引位置开始、包含所指定元素数的部分中第一个匹配项的从零开始的索引。

IndexOf(String, String)

搜索指定的子字符串并返回整个源字符串内第一个匹配项的从零开始的索引。

IndexOf(String, String, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回整个源字符串内第一个匹配项的从零开始的索引。

IndexOf(String, String, Int32)

搜索指定的子字符串,并返回源字符串内从指定的索引位置到字符串结尾这一部分中第一个匹配项的从零开始的索引。

IndexOf(String, String, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回源字符串内从指定的索引位置到字符串结尾这一部分中第一个匹配项的从零开始的索引。

IndexOf(String, String, Int32, Int32)

搜索指定的子字符串,并返回源字符串内从指定的索引位置开始、包含指定的元素数的部分中第一个匹配项的从零开始的索引。

IndexOf(String, String, Int32, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回源字符串内从指定的索引位置开始、包含所指定元素数的部分中第一个匹配项的从零开始的索引。

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

确定某一字符只读范围是否以指定前缀开头。

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

确定字符串是否以指定的前缀开头。

IsPrefix(String, String)

确定指定的源字符串是否以指定的前缀开头。

IsPrefix(String, String, CompareOptions)

使用指定的 CompareOptions 值确定指定的源字符串是否以指定的前缀开头。

IsSortable(Char)

指示指定的 Unicode 字符是否可排序。

IsSortable(ReadOnlySpan<Char>)

指示指定的 Unicode 字符只读范围是否可排序。

IsSortable(Rune)

指示指定的 Rune 是否可排序。

IsSortable(String)

指示指定的 Unicode 字符串是否可排序。

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

确定某一字符只读范围是否以指定后缀结尾。

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

确定字符串是否以特定的后缀结尾。

IsSuffix(String, String)

确定指定的源字符串是否以指定的后缀结尾。

IsSuffix(String, String, CompareOptions)

使用指定的 CompareOptions 值确定指定的源字符串是否以指定的后缀结尾。

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

在指定字符只读范围内搜索 substring 的最后一个匹配项。

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

在源字符串中搜索最后一次出现的子字符串。

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

在指定字符只读范围内搜索 Rune 的最后一个匹配项。

LastIndexOf(String, Char)

搜索指定的字符,并返回整个源字符串内最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回整个源字符串内最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char, Int32)

搜索指定的字符,并返回源字符串内从字符串开头到指定的索引位置这一部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回源字符串内从字符串开头到指定的索引位置这一部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char, Int32, Int32)

搜索指定的字符,并返回源字符串内包含指定的元素数、以指定的索引位置结尾的部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char, Int32, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的字符,并返回源字符串内包含所指定元素数、以指定的索引位置结尾的部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, String)

搜索指定的子字符串,并返回整个源字符串内最后一个匹配项的从零开始的索引。

LastIndexOf(String, String, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回整个源字符串内最后一个匹配项的从零开始的索引。

LastIndexOf(String, String, Int32)

搜索指定的子字符串,并返回源字符串内从字符串开头到指定的索引位置这一部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, String, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回源字符串内从字符串开头到指定的索引位置这一部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, String, Int32, Int32)

搜索指定的子字符串,并返回源字符串内包含指定的元素数、以指定的索引位置结尾的部分中最后一个匹配项的从零开始的索引。

LastIndexOf(String, String, Int32, Int32, CompareOptions)

使用指定的 CompareOptions 值,搜索指定的子字符串,并返回源字符串内包含所指定元素数、以指定的索引位置结尾的部分中最后一个匹配项的从零开始的索引。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前 CompareInfo 对象的字符串。

显式接口实现

IDeserializationCallback.OnDeserialization(Object)

在整个对象图形已经反序列化时运行。

扩展方法

GetStringComparer(CompareInfo, CompareOptions)

根据指定 CompareInfo 对象区分区域性的字符串比较规则,返回 StringComparer 对象。

适用于

另请参阅