StringComparer StringComparer StringComparer StringComparer Class

정의

특정 대/소문자 및 문화권 기반 또는 서수 비교 규칙을 사용하는 문자열 비교 연산을 나타냅니다.Represents a string comparison operation that uses specific case and culture-based or ordinal comparison rules.

public ref class StringComparer abstract : System::Collections::Generic::IComparer<System::String ^>, System::Collections::Generic::IEqualityComparer<System::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
    interface IEqualityComparer
    interface IComparer<string>
    interface IEqualityComparer<string>
Public MustInherit Class StringComparer
Implements IComparer, IComparer(Of String), IEqualityComparer, IEqualityComparer(Of String)
상속
StringComparerStringComparerStringComparerStringComparer
특성
구현

예제

다음 예제에서는 속성 및 Create 메서드는 StringComparer 클래스입니다.The following example demonstrates the properties and the Create method of the StringComparer class. 예제에 다양 한 StringComparer 개체 정렬 세 가지 버전의 라틴 문자 I.The example illustrates how different StringComparer objects sort three versions of the Latin letter I.

// This example demonstrates members of the
// System::StringComparer class.

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Globalization;
using namespace System::Threading;

void Display(List<String^>^ stringList, String^ title)
{
    Char firstChar;
    int codePoint;
    Console::WriteLine(title);
    for each (String^ s in stringList)
    {
        firstChar = s[0];
        codePoint = Convert::ToInt32(firstChar);
        Console::WriteLine("0x{0:x}", codePoint);
    }
    Console::WriteLine();
}

int main()
{
    // Create a list of string.
    List<String^>^ stringList = gcnew List<String^>();

    // Get the tr-TR (Turkish-Turkey) culture.
    CultureInfo^ turkishCulture = gcnew CultureInfo("tr-TR");

    // Get the culture that is associated with the current thread.
    CultureInfo^ currentCulture = Thread::CurrentThread->CurrentCulture;

    // Get the standard StringComparers.
    StringComparer^ invariant = StringComparer::InvariantCulture;
    StringComparer^ invariantIgnoreCase =
        StringComparer::InvariantCultureIgnoreCase;
    StringComparer^ current = StringComparer::CurrentCulture;
    StringComparer^ currentIgnoreCase =
        StringComparer::CurrentCultureIgnoreCase;
    StringComparer^ ordinal = StringComparer::Ordinal;
    StringComparer^ ordinalIgnoreCase = StringComparer::OrdinalIgnoreCase;

    // Create a StringComparer that uses the Turkish culture and ignores
    // case.
    StringComparer^ turkishIgnoreCase =
        StringComparer::Create(turkishCulture, 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 = L"\u0131";

    // Add the three strings to the list.
    stringList->Add(capitalLetterI);
    stringList->Add(smallLetterI);
    stringList->Add(smallLetterDotlessI);

    // Display the original list order.
    Display(stringList, "The original order of the list entries...");

    // Sort the list using the invariant culture.
    stringList->Sort(invariant);
    Display(stringList, "Invariant culture...");
    stringList->Sort(invariantIgnoreCase);
    Display(stringList, "Invariant culture, ignore case...");

    // Sort the list using the current culture.
    Console::WriteLine("The current culture is \"{0}\".",
        currentCulture->Name);
    stringList->Sort(current);
    Display(stringList, "Current culture...");
    stringList->Sort(currentIgnoreCase);
    Display(stringList, "Current culture, ignore case...");

    // Sort the list using the ordinal value of the character code points.
    stringList->Sort(ordinal);
    Display(stringList, "Ordinal...");
    stringList->Sort(ordinalIgnoreCase);
    Display(stringList, "Ordinal, ignore case...");

    // Sort the list using the Turkish culture, which treats LATIN SMALL
    // LETTER DOTLESS I differently than LATIN SMALL LETTER I.
    stringList->Sort(turkishIgnoreCase);
    Display(stringList, "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 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 code example demonstrates members of the System.StringComparer class.

Imports System
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 'Main
    
    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 'Display
End Class 'Sample '

'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
'

설명

파생 된 개체는 StringComparer 문자열 기반 비교, 같음 및 해시 코드 작업 모두 사례 및 문화권별 비교 규칙을 고려 하는 클래스를 구현 합니다.An object derived from the StringComparer class embodies string-based comparison, equality, and hash code operations that take into account both case and culture-specific comparison rules. 사용할 수는 StringComparer 제네릭 컬렉션에서 요소를 정렬 하는 형식별 비교를 만드는 클래스입니다.You can use the StringComparer class to create a type-specific comparison to sort the elements in a generic collection. 와 같은 클래스 Hashtable, Dictionary<TKey,TValue>SortedList, 및 SortedList<TKey,TValue> 사용 하 여는 StringComparer 가나가 클래스입니다.Classes such as Hashtable, Dictionary<TKey,TValue>, SortedList, and SortedList<TKey,TValue> use the StringComparer class for sorting purposes.

표현 하는 비교 연산을 StringComparer 을 대/소문자 구분 또는 대/소문자, 단어 (문화권 구분)를 사용 하 여 정의 또는 서 수 (문화권) 비교 규칙입니다.A comparison operation that is represented by the StringComparer class is defined to be either case-sensitive or case-insensitive, and use either word (culture-sensitive) or ordinal (culture-insensitive) comparison rules. Word 및 서 수 비교 규칙에 대 한 자세한 내용은 참조 하세요. System.Globalization.CompareOptions합니다.For more information about word and ordinal comparison rules, see System.Globalization.CompareOptions.

참고

Windows 운영 체제에 대한 정렬 및 비교 작업에 사용되는 문자 가중치에 대한 정보를 포함하는 텍스트 파일 집합인 정렬 가중치 테이블 및 Linux 및 macOS용 정렬 가중치 테이블의 최신 버전인 기본 유니코드 데이터 정렬 요소 테이블을 다운로드할 수 있습니다.You can download the Sorting Weight Tables, a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, and the Default Unicode Collation Element Table, the latest version of the sort weight table for Linux and macOS. Linux 및 macOS에서 정렬 가중치 테이블의 특정 버전은 시스템에 설치된 International Components for Unicode 라이브러리 버전에 따라 달라집니다.The specific version of the sort weight table on Linux and macOS depends on the version of the International Components for Unicode libraries installed on the system. ICU 버전 및 ICU 버전이 구현하는 유니코드 버전에 대한 자세한 내용은 ICU 다운로드를 참조하세요.For information on ICU versions and the Unicode versions that they implement, see Downloading ICU.

구현 된 속성Implemented properties

사용 하는 방법에 대 한 혼동 될 수 있습니다는 StringComparer 모순 처럼 보이기 때문에 클래스 속성입니다.You might be confused about how to use the StringComparer class properties because of a seeming contradiction. StringComparer 클래스를 선언 abstract (MustInherit Visual basic에서)에서 파생 된 클래스의 개체에만 즉, 해당 멤버를 호출할 수 있습니다는 StringComparer 클래스.The StringComparer class is declared abstract (MustInherit in Visual Basic), which means its members can be invoked only on an object of a class derived from the StringComparer class. 모순은의 각 속성을 StringComparer 클래스를 선언 static (Shared Visual Basic의), 속성 즉, 먼저 파생된 클래스를 만들지 않고 호출할 수 있습니다.The contradiction is that each property of the StringComparer class is declared static (Shared in Visual Basic), which means the property can be invoked without first creating a derived class.

호출할 수 있습니다는 StringComparer 속성을 직접 각 속성에서 파생 되는 익명 클래스의 인스턴스를 실제로 반환 하기 때문에 StringComparer 클래스입니다.You can call a StringComparer property directly because each property actually returns an instance of an anonymous class that is derived from the StringComparer class. 따라서 각 속성 값의 형식이 StringComparer, 익명 클래스의 기본 클래스를 되지 않는 익명 형식의 클래스 자체입니다.Consequently, the type of each property value is StringComparer, which is the base class of the anonymous class, not the type of the anonymous class itself. StringComparer 속성이 반환 클래스는 StringComparer 미리 정의 된 경우 및 비교 규칙을 지 원하는 개체입니다.Each StringComparer class property returns a StringComparer object that supports predefined case and comparison rules.

생성자

StringComparer() StringComparer() StringComparer() StringComparer()

StringComparer 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the StringComparer class.

속성

CurrentCulture CurrentCulture CurrentCulture CurrentCulture

현재 문화권의 단어 비교 규칙을 사용하여 대/소문자를 구분하는 문자열을 비교하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs a case-sensitive string comparison using the word comparison rules of the current culture.

CurrentCultureIgnoreCase CurrentCultureIgnoreCase CurrentCultureIgnoreCase CurrentCultureIgnoreCase

현재 문화권의 단어 비교 규칙을 사용하여 대/소문자를 구분하지 않는 문자열을 비교하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs case-insensitive string comparisons using the word comparison rules of the current culture.

InvariantCulture InvariantCulture InvariantCulture InvariantCulture

고정 문화권의 단어 비교 규칙을 사용하여 대/소문자를 구분하는 문자열 비교를 수행하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture.

InvariantCultureIgnoreCase InvariantCultureIgnoreCase InvariantCultureIgnoreCase InvariantCultureIgnoreCase

고정 문화권의 단어 비교 규칙을 사용하여 대/소문자를 구분하지 않는 문자열 비교를 수행하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture.

Ordinal Ordinal Ordinal Ordinal

대/소문자를 구분하는 서수 문자열 비교를 수행하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs a case-sensitive ordinal string comparison.

OrdinalIgnoreCase OrdinalIgnoreCase OrdinalIgnoreCase OrdinalIgnoreCase

대/소문자를 구분하지 않는 서수 문자열 비교를 수행하는 StringComparer 개체를 가져옵니다.Gets a StringComparer object that performs a case-insensitive ordinal string comparison.

메서드

Compare(Object, Object) Compare(Object, Object) Compare(Object, Object) Compare(Object, Object)

파생 클래스에서 재정의된 경우 두 개체를 비교하고 상대적 정렬 순서를 나타내는 값을 반환합니다.When overridden in a derived class, compares two objects and returns an indication of their relative sort order.

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

파생 클래스에서 재정의된 경우 두 문자열을 비교하고 상대적 정렬 순서를 나타내는 값을 반환합니다.When overridden in a derived class, compares two strings and returns an indication of their relative sort order.

Create(CultureInfo, Boolean) Create(CultureInfo, Boolean) Create(CultureInfo, Boolean) Create(CultureInfo, Boolean)

지정된 문화권의 규칙에 따라 문자열을 비교하는 StringComparer 개체를 만듭니다.Creates a StringComparer object that compares strings according to the rules of a specified culture.

Create(CultureInfo, CompareOptions) Create(CultureInfo, CompareOptions) Create(CultureInfo, CompareOptions) Create(CultureInfo, CompareOptions)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
Equals(Object, Object) Equals(Object, Object) Equals(Object, Object) Equals(Object, Object)

파생 클래스에서 재정의된 경우 두 개체가 같음을 나타냅니다.When overridden in a derived class, indicates whether two objects are equal.

Equals(String, String) Equals(String, String) Equals(String, String) Equals(String, String)

파생 클래스에서 재정의된 경우 두 문자열이 같음을 나타냅니다.When overridden in a derived class, indicates whether two strings are equal.

FromComparison(StringComparison) FromComparison(StringComparison) FromComparison(StringComparison) FromComparison(StringComparison)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetHashCode(Object) GetHashCode(Object) GetHashCode(Object) GetHashCode(Object)

파생 클래스에서 재정의된 경우 지정된 개체의 해시 코드를 가져옵니다.When overridden in a derived class, gets the hash code for the specified object.

GetHashCode(String) GetHashCode(String) GetHashCode(String) GetHashCode(String)

파생 클래스에서 재정의된 경우 지정된 문자열의 해시 코드를 가져옵니다.When overridden in a derived class, gets the hash code for the specified string.

GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

명시적 인터페이스 구현

IComparer.Compare(Object, Object) IComparer.Compare(Object, Object) IComparer.Compare(Object, Object) IComparer.Compare(Object, Object)
IEqualityComparer.Equals(Object, Object) IEqualityComparer.Equals(Object, Object) IEqualityComparer.Equals(Object, Object) IEqualityComparer.Equals(Object, Object)
IEqualityComparer.GetHashCode(Object) IEqualityComparer.GetHashCode(Object) IEqualityComparer.GetHashCode(Object) IEqualityComparer.GetHashCode(Object)

적용 대상

추가 정보