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

注解

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

示例

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

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

属性

名称 说明
LCID

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

Name

获取用于按此 CompareInfo 对象对操作进行排序的区域性的名称。

Version

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

方法

名称 说明
Compare(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

比较两个只读字符范围。

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

使用指定 CompareOptions 值将一个字符串的节与另一个字符串的节进行比较。

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

将一个字符串的节与另一个字符串的节进行比较。

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

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

Compare(String, Int32, String, Int32)

将字符串的结束部分与另一个字符串的结束部分进行比较。

Compare(String, String, CompareOptions)

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

Compare(String, String)

比较两个字符串。

Equals(Object)

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

GetCompareInfo(Int32, Assembly)

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

GetCompareInfo(Int32)

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

GetCompareInfo(String, Assembly)

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

GetCompareInfo(String)

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

GetHashCode()

用作哈希算法和数据结构的当前 CompareInfo 哈希函数,例如哈希表。

GetHashCode(ReadOnlySpan<Char>, CompareOptions)

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

GetHashCode(String, CompareOptions)

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

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

计算指定输入的排序键。

GetSortKey(String, CompareOptions)

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

GetSortKey(String)

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

GetSortKeyLength(ReadOnlySpan<Char>, CompareOptions)

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

GetType()

获取当前实例的 Type

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

搜索源字符串中子字符串的第一个匹配项。

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

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

IndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

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

IndexOf(String, Char, CompareOptions)

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

IndexOf(String, Char, Int32, CompareOptions)

搜索指定的字符并返回源字符串节中第一个匹配项的从零开始的索引,该索引使用指定的 CompareOptions 值从指定的索引扩展到字符串的末尾。

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

搜索指定的字符并返回源字符串的节中第一个匹配项的从零开始的索引,该索引从指定索引开始,并包含使用指定值的指定 CompareOptions 数量的元素。

IndexOf(String, Char, Int32, Int32)

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

IndexOf(String, Char, Int32)

搜索指定的字符,并返回源字符串节中从指定索引扩展到字符串末尾的第一个匹配项的从零开始的索引。

IndexOf(String, Char)

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

IndexOf(String, String, CompareOptions)

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

IndexOf(String, String, Int32, CompareOptions)

搜索指定的子字符串,并使用指定的值返回源字符串节中第一个匹配项的从零开始的索引,该索引从指定的 CompareOptions 索引扩展到字符串的末尾。

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

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

IndexOf(String, String, Int32, Int32)

搜索指定的子字符串,并返回源字符串节中从指定索引开始且包含指定数量的元素的第一个匹配项的从零开始的索引。

IndexOf(String, String, Int32)

搜索指定的子字符串,并返回源字符串节中从指定索引扩展到字符串末尾的第一个匹配项的从零开始的索引。

IndexOf(String, String)

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

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

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

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

确定字符的只读范围是否以特定前缀开头。

IsPrefix(String, String, CompareOptions)

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

IsPrefix(String, String)

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

IsSortable(Char)

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

IsSortable(ReadOnlySpan<Char>)

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

IsSortable(Rune)

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

IsSortable(String)

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

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

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

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

确定字符的只读范围是否以特定的后缀结尾。

IsSuffix(String, String, CompareOptions)

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

IsSuffix(String, String)

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

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

搜索源字符串中子字符串的最后一个匹配项。

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

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

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

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

LastIndexOf(String, Char, CompareOptions)

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

LastIndexOf(String, Char, Int32, CompareOptions)

搜索指定的字符,并返回源字符串节中最后一个匹配项的从开始到指定索引(使用指定值从字符串开头扩展到指定 CompareOptions 索引)的从零开始的索引。

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

搜索指定的字符,并返回源字符串节中最后一个匹配项的从零开始的索引,该节包含指定数量的元素,并使用指定的值在指定 CompareOptions 索引处结束。

LastIndexOf(String, Char, Int32, Int32)

搜索指定的字符,并返回源字符串的节中最后一个匹配项的从零开始的索引,该节包含指定数量的元素并在指定索引处结束。

LastIndexOf(String, Char, Int32)

搜索指定的字符,并返回源字符串节中从字符串开头扩展到指定索引的最后一个匹配项的从零开始的索引。

LastIndexOf(String, Char)

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

LastIndexOf(String, String, CompareOptions)

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

LastIndexOf(String, String, Int32, CompareOptions)

搜索指定的子字符串,并返回源字符串的节中最后一个匹配项的从零开始的索引,该索引从字符串的开头扩展到使用指定的值指定的 CompareOptions 索引。

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

搜索指定的子字符串,并使用指定的值返回源字符串节中最后一个匹配项的从零开始的索引,该索引包含指定数量的元素,并在指定 CompareOptions 索引处结束。

LastIndexOf(String, String, Int32, Int32)

搜索指定的子字符串,并返回源字符串节中最后一个匹配项的从零开始的索引,该节包含指定数量的元素,并在指定索引处结束。

LastIndexOf(String, String, Int32)

搜索指定的子字符串,并在源字符串的节中返回从字符串开头扩展到指定索引的最后一个匹配项的从零开始的索引。

LastIndexOf(String, String)

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

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

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

显式接口实现

名称 说明
IDeserializationCallback.OnDeserialization(Object)

反序列化整个对象图时运行。

扩展方法

名称 说明
GetStringComparer(CompareInfo, CompareOptions)

StringComparer基于指定CompareInfo对象的区域性敏感字符串比较规则返回对象。

适用于

另请参阅