StringComparer Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirli büyük/küçük harf ve kültür tabanlı veya sıralı karşılaştırma kurallarını kullanan bir dize karşılaştırma işlemini temsil eder.
public ref class StringComparer abstract : System::Collections::Generic::IComparer<System::String ^>, System::Collections::Generic::IEqualityComparer<System::String ^>, System::Collections::IComparer, System::Collections::IEqualityComparer
public abstract class StringComparer : System.Collections.Generic.IComparer<string>, System.Collections.Generic.IEqualityComparer<string>, System.Collections.IComparer, System.Collections.IEqualityComparer
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public abstract class StringComparer : System.Collections.Generic.IComparer<string>, System.Collections.Generic.IEqualityComparer<string>, System.Collections.IComparer, System.Collections.IEqualityComparer
type StringComparer = class
interface IComparer<string>
interface IEqualityComparer<string>
interface IComparer
interface IEqualityComparer
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type StringComparer = class
interface IComparer
interface IEqualityComparer
interface IComparer<string>
interface IEqualityComparer<string>
Public MustInherit Class StringComparer
Implements IComparer, IComparer(Of String), IEqualityComparer, IEqualityComparer(Of String)
- Devralma
-
StringComparer
- Öznitelikler
- Uygulamalar
Örnekler
Aşağıdaki örnek, sınıfının özelliklerini ve Create yöntemini StringComparer gösterir. Örnek, farklı StringComparer nesnelerin I Latin harfinin üç sürümünü nasıl sıralayanı gösterir.
// This example demonstrates members of the
// System.StringComparer class.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
class Sample
{
public static void Main()
{
// Create a list of string.
List<string> list = new List<string>();
// Get the tr-TR (Turkish-Turkey) culture.
CultureInfo turkish = new CultureInfo("tr-TR");
// Get the culture that is associated with the current thread.
CultureInfo thisCulture = Thread.CurrentThread.CurrentCulture;
// Get the standard StringComparers.
StringComparer invCmp = StringComparer.InvariantCulture;
StringComparer invICCmp = StringComparer.InvariantCultureIgnoreCase;
StringComparer currCmp = StringComparer.CurrentCulture;
StringComparer currICCmp = StringComparer.CurrentCultureIgnoreCase;
StringComparer ordCmp = StringComparer.Ordinal;
StringComparer ordICCmp = StringComparer.OrdinalIgnoreCase;
// Create a StringComparer that uses the Turkish culture and ignores case.
StringComparer turkICComp = StringComparer.Create(turkish, true);
// Define three strings consisting of different versions of the letter I.
// LATIN CAPITAL LETTER I (U+0049)
string capitalLetterI = "I";
// LATIN SMALL LETTER I (U+0069)
string smallLetterI = "i";
// LATIN SMALL LETTER DOTLESS I (U+0131)
string smallLetterDotlessI = "\u0131";
// Add the three strings to the list.
list.Add(capitalLetterI);
list.Add(smallLetterI);
list.Add(smallLetterDotlessI);
// Display the original list order.
Display(list, "The original order of the list entries...");
// Sort the list using the invariant culture.
list.Sort(invCmp);
Display(list, "Invariant culture...");
list.Sort(invICCmp);
Display(list, "Invariant culture, ignore case...");
// Sort the list using the current culture.
Console.WriteLine("The current culture is \"{0}\".", thisCulture.Name);
list.Sort(currCmp);
Display(list, "Current culture...");
list.Sort(currICCmp);
Display(list, "Current culture, ignore case...");
// Sort the list using the ordinal value of the character code points.
list.Sort(ordCmp);
Display(list, "Ordinal...");
list.Sort(ordICCmp);
Display(list, "Ordinal, ignore case...");
// Sort the list using the Turkish culture, which treats LATIN SMALL LETTER
// DOTLESS I differently than LATIN SMALL LETTER I.
list.Sort(turkICComp);
Display(list, "Turkish culture, ignore case...");
}
public static void Display(List<string> lst, string title)
{
Char c;
int codePoint;
Console.WriteLine(title);
foreach (string s in lst)
{
c = s[0];
codePoint = Convert.ToInt32(c);
Console.WriteLine("0x{0:x}", codePoint);
}
Console.WriteLine();
}
}
/*
This code example produces the following results:
The original order of the list entries...
0x49
0x69
0x131
Invariant culture...
0x69
0x49
0x131
Invariant culture, ignore case...
0x49
0x69
0x131
The current culture is "en-US".
Current culture...
0x69
0x49
0x131
Current culture, ignore case...
0x49
0x69
0x131
Ordinal...
0x49
0x69
0x131
Ordinal, ignore case...
0x69
0x49
0x131
Turkish culture, ignore case...
0x131
0x49
0x69
*/
// This example demonstrates members of the
// System.StringComparer class.
open System
open System.Globalization
open System.Threading
let display (lst: ResizeArray<string>) title =
printfn $"%s{title}"
for s in lst do
let c = s[0]
let codePoint = Convert.ToInt32 c
printfn $"0x{codePoint:x}"
printfn ""
// Create a list of string.
let list = ResizeArray()
// Get the tr-TR (Turkish-Turkey) culture.
let turkish = CultureInfo "tr-TR"
// Get the culture that is associated with the current thread.
let thisCulture = Thread.CurrentThread.CurrentCulture
// Get the standard StringComparers.
let invCmp = StringComparer.InvariantCulture
let invICCmp = StringComparer.InvariantCultureIgnoreCase
let currCmp = StringComparer.CurrentCulture
let currICCmp = StringComparer.CurrentCultureIgnoreCase
let ordCmp = StringComparer.Ordinal
let ordICCmp = StringComparer.OrdinalIgnoreCase
// Create a StringComparer that uses the Turkish culture and ignores case.
let turkICComp = StringComparer.Create(turkish, true)
// Define three strings consisting of different versions of the letter I.
// LATIN CAPITAL LETTER I (U+0049)
let capitalLetterI = "I"
// LATIN SMALL LETTER I (U+0069)
let smallLetterI = "i"
// LATIN SMALL LETTER DOTLESS I (U+0131)
let smallLetterDotlessI = "\u0131"
// Add the three strings to the list.
list.Add capitalLetterI
list.Add smallLetterI
list.Add smallLetterDotlessI
// Display the original list order.
display list "The original order of the list entries..."
// Sort the list using the invariant culture.
list.Sort invCmp
display list "Invariant culture..."
list.Sort invICCmp
display list "Invariant culture, ignore case..."
// Sort the list using the current culture.
printfn $"The current culture is \"{thisCulture.Name}\"."
list.Sort currCmp
display list "Current culture..."
list.Sort currICCmp
display list "Current culture, ignore case..."
// Sort the list using the ordinal value of the character code points.
list.Sort ordCmp
display list "Ordinal..."
list.Sort ordICCmp
display list "Ordinal, ignore case..."
// Sort the list using the Turkish culture, which treats LATIN SMALL LETTER
// DOTLESS I differently than LATIN SMALL LETTER I.
list.Sort turkICComp
display list "Turkish culture, ignore case..."
(*
This code example produces the following results:
The original order of the list entries...
0x49
0x69
0x131
Invariant culture...
0x69
0x49
0x131
Invariant culture, ignore case...
0x49
0x69
0x131
The current culture is "en-US".
Current culture...
0x69
0x49
0x131
Current culture, ignore case...
0x49
0x69
0x131
Ordinal...
0x49
0x69
0x131
Ordinal, ignore case...
0x69
0x49
0x131
Turkish culture, ignore case...
0x131
0x49
0x69
*)
' This code example demonstrates members of the System.StringComparer class.
Imports System.Collections
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Threading
Class Sample
Public Shared Sub Main()
' Create a list of string.
Dim list As New List(Of String)
' Get the tr-TR (Turkish-Turkey) culture.
Dim turkish As New CultureInfo("tr-TR")
' Get the culture that is associated with the current thread.
Dim thisCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
' Get the standard StringComparers.
Dim invCmp As StringComparer = StringComparer.InvariantCulture
Dim invICCmp As StringComparer = StringComparer.InvariantCultureIgnoreCase
Dim currCmp As StringComparer = StringComparer.CurrentCulture
Dim currICCmp As StringComparer = StringComparer.CurrentCultureIgnoreCase
Dim ordCmp As StringComparer = StringComparer.Ordinal
Dim ordICCmp As StringComparer = StringComparer.OrdinalIgnoreCase
' Create a StringComparer that uses the Turkish culture and ignores case.
Dim turkICComp As StringComparer = StringComparer.Create(turkish, True)
' Define three strings consisting of different versions of the letter I.
' LATIN CAPITAL LETTER I (U+0049)
Dim capitalLetterI As String = "I"
' LATIN SMALL LETTER I (U+0069)
Dim smallLetterI As String = "i"
' LATIN SMALL LETTER DOTLESS I (U+0131)
Dim smallLetterDotlessI As String = "ı"
' Add the three strings to the list.
list.Add(capitalLetterI)
list.Add(smallLetterI)
list.Add(smallLetterDotlessI)
' Display the original list order.
Display(list, "The original order of the list entries...")
' Sort the list using the invariant culture.
list.Sort(invCmp)
Display(list, "Invariant culture...")
list.Sort(invICCmp)
Display(list, "Invariant culture, ignore case...")
' Sort the list using the current culture.
Console.WriteLine("The current culture is ""{0}"".", thisCulture.Name)
list.Sort(currCmp)
Display(list, "Current culture...")
list.Sort(currICCmp)
Display(list, "Current culture, ignore case...")
' Sort the list using the ordinal value of the character code points.
list.Sort(ordCmp)
Display(list, "Ordinal...")
list.Sort(ordICCmp)
Display(list, "Ordinal, ignore case...")
' Sort the list using the Turkish culture, which treats LATIN SMALL LETTER
' DOTLESS I differently than LATIN SMALL LETTER I.
list.Sort(turkICComp)
Display(list, "Turkish culture, ignore case...")
End Sub
Public Shared Sub Display(ByVal lst As List(Of String), ByVal title As String)
Dim c As Char
Dim s As String
Dim codePoint As Integer
Console.WriteLine(title)
For Each s In lst
c = s(0)
codePoint = Convert.ToInt32(c)
Console.WriteLine("0x{0:x}", codePoint)
Next s
Console.WriteLine()
End Sub
End Class
'This code example produces the following results:
'
'The original order of the list entries...
'0x49
'0x69
'0x131
'
'Invariant culture...
'0x69
'0x49
'0x131
'
'Invariant culture, ignore case...
'0x49
'0x69
'0x131
'
'The current culture is "en-US".
'Current culture...
'0x69
'0x49
'0x131
'
'Current culture, ignore case...
'0x49
'0x69
'0x131
'
'Ordinal...
'0x49
'0x69
'0x131
'
'Ordinal, ignore case...
'0x69
'0x49
'0x131
'
'Turkish culture, ignore case...
'0x131
'0x49
'0x69
'
Açıklamalar
Bu API hakkında daha fazla bilgi için bkz . StringComparer için ek API açıklamaları.
Oluşturucular
| Name | Description |
|---|---|
| StringComparer() |
StringComparer sınıfının yeni bir örneğini başlatır. |
Özellikler
| Name | Description |
|---|---|
| CurrentCulture |
Geçerli kültürün sözcük karşılaştırma kurallarını kullanarak büyük/küçük harfe duyarlı dize karşılaştırması gerçekleştiren bir StringComparer nesne alır. |
| CurrentCultureIgnoreCase |
Geçerli kültürün sözcük karşılaştırma kurallarını kullanarak büyük/küçük harfe duyarlı olmayan dize karşılaştırmaları gerçekleştiren bir StringComparer nesne alır. |
| InvariantCulture |
Sabit kültürün sözcük karşılaştırma kurallarını kullanarak büyük/küçük harfe duyarlı dize karşılaştırması gerçekleştiren bir StringComparer nesne alır. |
| InvariantCultureIgnoreCase |
Sabit kültürün sözcük karşılaştırma kurallarını kullanarak büyük/küçük harfe duyarsız dize karşılaştırması gerçekleştiren bir StringComparer nesne alır. |
| Ordinal |
StringComparer Büyük/küçük harfe duyarlı sıralı dize karşılaştırması gerçekleştiren bir nesne alır. |
| OrdinalIgnoreCase |
StringComparer Büyük/küçük harfe duyarlı olmayan sıralı dize karşılaştırması gerçekleştiren bir nesne alır. |
Yöntemler
| Name | Description |
|---|---|
| Compare(Object, Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, iki nesneyi karşılaştırır ve göreli sıralama düzenlerinin bir göstergesini döndürür. |
| Compare(String, String) |
Türetilmiş bir sınıfta geçersiz kılındığında, iki dizeyi karşılaştırır ve göreli sıralama düzenlerinin bir göstergesini döndürür. |
| Create(CultureInfo, Boolean) |
StringComparer Dizeleri belirtilen kültürün kurallarına göre karşılaştıran bir nesne oluşturur. |
| Create(CultureInfo, CompareOptions) |
Dizeleri belirtilen kültür StringComparer ve dize seçeneklerinin kurallarına göre karşılaştıran bir nesne oluşturur. |
| Equals(Object, Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, iki nesnenin eşit olup olmadığını gösterir. |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| Equals(String, String) |
Türetilmiş bir sınıfta geçersiz kılındığında, iki dizenin eşit olup olmadığını gösterir. |
| FromComparison(StringComparison) |
Belirtilen StringComparison örneği bir StringComparer örneğe dönüştürür. |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetHashCode(Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, belirtilen nesnenin karma kodunu alır. |
| GetHashCode(String) |
Türetilmiş bir sınıfta geçersiz kılındığında, belirtilen dize için karma kodu alır. |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| IsWellKnownCultureAwareComparer(IEqualityComparer<String>, CompareInfo, CompareOptions) |
Belirtilen IEqualityComparer<T> değerin iyi bilinen bir kültür algılamalı dize karşılaştırıcısı olup olmadığını belirler. |
| IsWellKnownOrdinalComparer(IEqualityComparer<String>, Boolean) |
Belirtilenin IEqualityComparer<T> iyi bilinen bir sıralı dize karşılaştırıcısı olup olmadığını belirler. |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
| Name | Description |
|---|---|
| IComparer.Compare(Object, Object) |
İki nesneyi karşılaştırır ve birinin diğerinden küçük, eşit veya daha büyük olduğunu belirten bir değer döndürür. |
| IEqualityComparer.Equals(Object, Object) |
Belirtilen nesnelerin eşit olup olmadığını belirler. |
| IEqualityComparer.GetHashCode(Object) |
Belirtilen nesne için bir karma kodu döndürür. |