StringComparer.InvariantCulture プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringComparer.InvariantCulture プロパティの意味・解説 

StringComparer.InvariantCulture プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

インバリアント カルチャの単語ベース比較規則使用して大文字と小文字区別して文字列比較する StringComparer オブジェクト取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared ReadOnly Property
 InvariantCulture As StringComparer
Dim value As StringComparer

value = StringComparer.InvariantCulture
public static StringComparer InvariantCulture
 { get; }
public:
static property StringComparer^ InvariantCulture {
    StringComparer^ get ();
}
/** @property */
public static StringComparer get_InvariantCulture
 ()
public static function get
 InvariantCulture () : StringComparer

プロパティ
新しStringComparer オブジェクト

解説解説

インバリアント カルチャは、InvariantCulture プロパティから返される CultureInfo オブジェクトです。

実際には、InvariantCulture プロパティは、StringComparer クラスから派生した匿名クラスインスタンス返します

使用例使用例

StringComparer クラスプロパティおよび Create メソッド使ったコード例次に示します。この例は、StringComparer オブジェクトによって 3 種類のラテン文字「I」それぞれどのように並べ替えられるかを示してます。

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

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

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StringComparer クラス
StringComparer メンバ
System 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「StringComparer.InvariantCulture プロパティ」の関連用語

StringComparer.InvariantCulture プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringComparer.InvariantCulture プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS