CompareInfo 類別

定義

實作區分文化特性 (Culture) 的字串比較的一組方法。

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
屬性
實作

範例

下列範例顯示與 CultureInfo 對象相關聯的 物件如何影響CompareInfo字串比較。

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)

在所指定唯讀字元範圍中搜尋第一個出現的子字串。

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)

在所指定唯讀字元範圍中搜尋最後一個出現的子字串。

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)

執行於整個物件 Graph 已經還原序列化時。

擴充方法

GetStringComparer(CompareInfo, CompareOptions)

根據所指定之 CompareInfo 物件的區分文化特性字串比較規則,傳回 StringComparer 物件。

適用於

另請參閱