SortKey.ToString メソッドとは? わかりやすく解説

SortKey.ToString メソッド

現在の SortKey オブジェクトを表す文字列を返します

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

解説解説

戻り値は、文字列 "SortKey - "、現在の SortKey オブジェクトのカルチャ識別子比較オプション、および OriginalString プロパティの値を連結した値です。

このメソッドは、Object.ToString をオーバーライドます。

使用例使用例

元の文字列ToString メソッド大文字と小文字区別する並べ替えキー区別しない並べ替えキー使用して生成される文字列、および大文字と小文字区別する並べ替えキー区別しない並べ替えキーキー データ表示するコード例次に示します

' This code example demonstrates the 
' GetSortKey() and ToString() methods, and the 
' OriginalString and KeyData properties of the 
' System.Globalization.SortKey class.

Imports System
Imports System.Globalization

Class Sample
    Public Shared Sub Main()
 
        Dim cmpi As CompareInfo = Nothing
        Dim sk1 As SortKey = Nothing
        Dim sk2 As SortKey = Nothing
        Dim s As String
 = "ABC"
        Dim ignoreCase As String
 = "Ignore case"
        Dim useCase As String
 =    "Use case   "
        
        ' Get a CompareInfo object for the English-Great Britain culture.
        cmpi = CompareInfo.GetCompareInfo("en-GB")
        
        ' Get a sort key that ignores case for the specified string.
        sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase)
        ' Get a sort key with no compare option for the specified string.
        sk2 = cmpi.GetSortKey(s)
        
        ' Display the original string.
        Console.WriteLine("Original string: ""{0}""",
 sk1.OriginalString)
        Console.WriteLine()
        
        ' Display the the string equivalent of the two sort keys.
        Console.WriteLine("CompareInfo (culture) name: {0}",
 cmpi.Name)
        Console.WriteLine("ToString - {0}: ""{1}""",
 ignoreCase, sk1.ToString())
        Console.WriteLine("ToString - {0}: ""{1}""",
 useCase, sk2.ToString())
        Console.WriteLine()
        
        ' Display the key data of the two sort keys.
        DisplayKeyData(sk1, ignoreCase)
        DisplayKeyData(sk2, useCase)
    End Sub 'Main
    
    Public Shared Sub DisplayKeyData(ByVal
 sk As SortKey, ByVal title As
 String) 
        Console.Write("Key Data - {0}: ", title)
        Dim keyDatum As UInteger
        For Each keyDatum In
 sk.KeyData
            Console.Write("0x{0} ", CUInt(keyDatum))
        Next keyDatum
        Console.WriteLine()
    End Sub 'DisplayKeyData
End Class 'Sample

'
'This code example produces the following results:
'
'Original string: "ABC"
'
'CompareInfo (culture) name: en-GB
'ToString - Ignore case: "SortKey - 2057, IgnoreCase, ABC"
'ToString - Use case   : "SortKey - 2057, None, ABC"
'
'Key Data - Ignore case: 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x1 0x1
 0x0
'Key Data - Use case   : 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x18 0x18
 0x18 0x1 0x1 0x0
'
// This code example demonstrates the 
// GetSortKey() and ToString() methods, and the 
// OriginalString and KeyData properties of the 
// System.Globalization.SortKey class.

using System;
using System.Globalization;

class Sample 
{
    public static void Main()
 
    {
    CompareInfo cmpi = null;
    SortKey sk1 = null;
    SortKey sk2 = null;
    string s = "ABC";
    string ignoreCase = "Ignore case";
    string useCase    = "Use case   ";

// Get a CompareInfo object for the English-Great Britain culture.
    cmpi = CompareInfo.GetCompareInfo("en-GB");

// Get a sort key that ignores case for the specified string.
    sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase);
// Get a sort key with no compare option for the specified string.
    sk2 = cmpi.GetSortKey(s);

// Display the original string.
    Console.WriteLine("Original string: \"{0}\"",
 sk1.OriginalString);
    Console.WriteLine();

// Display the the string equivalent of the two sort keys.
    Console.WriteLine("CompareInfo (culture) name: {0}", cmpi.Name);
    Console.WriteLine("ToString - {0}: \"{1}\"", ignoreCase,
 sk1.ToString());
    Console.WriteLine("ToString - {0}: \"{1}\"", useCase, sk2.ToString());
    Console.WriteLine();

// Display the key data of the two sort keys.
    DisplayKeyData(sk1, ignoreCase);
    DisplayKeyData(sk2, useCase);
    }

    public static void DisplayKeyData(SortKey
 sk, string title)
    {
    Console.Write("Key Data - {0}: ", title);
    foreach (byte keyDatum in sk.KeyData)
        Console.Write("0x{0} ", (uint)keyDatum);
    Console.WriteLine();
    }
}
/*
This code example produces the following results:

Original string: "ABC"

CompareInfo (culture) name: en-GB
ToString - Ignore case: "SortKey - 2057, IgnoreCase, ABC"
ToString - Use case   : "SortKey - 2057, None, ABC"

Key Data - Ignore case: 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x1
 0x1 0x0
Key Data - Use case   : 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x18
 0x18 0x18 0x1 0x1 0x0

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

SortKey.ToString メソッドのお隣キーワード
検索ランキング

   

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



SortKey.ToString メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS