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

屬性

名稱 Description
LCID

取得當前 CompareInfo的正確文化識別碼。

Name

取得此物件用於排序操作 CompareInfo 的文化名稱。

Version

取得用於字串比較與排序的 Unicode 版本資訊。

方法

名稱 Description
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 與指定文化相關聯的新物件,該物件使用指定的 AssemblyDomain 中字串比較方法。

GetCompareInfo(Int32)

初始化一個與指定識別碼文化相關聯的新 CompareInfo 物件。

GetCompareInfo(String, Assembly)

初始化一個 CompareInfo 與指定文化相關聯的新物件,該物件使用指定的 AssemblyDomain 中字串比較方法。

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 物件的字串。

明確介面實作

名稱 Description
IDeserializationCallback.OnDeserialization(Object)

當整個物件圖都被反序列化時執行。

擴充方法

名稱 Description
GetStringComparer(CompareInfo, CompareOptions)

根據指定StringComparer物件的文化敏感字串比較規則回傳物件CompareInfo

適用於

另請參閱