本文整理汇总了VB.NET中System.Globalization.SortKey类的典型用法代码示例。如果您正苦于以下问题:VB.NET SortKey类的具体用法?VB.NET SortKey怎么用?VB.NET SortKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SortKey类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesSortKey
' 导入命名空间
Imports System.Globalization
Public Class SamplesSortKey
Public Shared Sub Main()
' Creates a SortKey using the en-US culture.
Dim myComp_enUS As CompareInfo = New CultureInfo("en-US", False).CompareInfo
Dim mySK1 As SortKey = myComp_enUS.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with international sort.
Dim myComp_esES As CompareInfo = New CultureInfo("es-ES", False).CompareInfo
Dim mySK2 As SortKey = myComp_esES.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with traditional sort.
Dim myComp_es As CompareInfo = New CultureInfo(&H40A, False).CompareInfo
Dim mySK3 As SortKey = myComp_es.GetSortKey("llama")
' Compares the en-US SortKey with each of the es-ES SortKey objects.
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with international sort : {0}", SortKey.Compare(mySK1, mySK2))
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with traditional sort : {0}", SortKey.Compare(mySK1, mySK3))
End Sub
End Class
输出:
Comparing "llama" in en-US and in es-ES with international sort : 0 Comparing "llama" in en-US and in es-ES with traditional sort : -1
示例2: Example
' 导入命名空间
Imports System.Globalization
Module Example
Public Sub Main()
' Define names.
Dim names() As String = { "Adam", "Ignatius", "Batholomew",
"Gregory", "Clement", "Frances",
"Harold", "Dalmatius", "Edgar",
"John", "Benedict", "Paul", "George" }
Dim sortKeys(names.Length - 1) As SortKey
Dim ci As CompareInfo = CultureInfo.CurrentCulture.CompareInfo
For ctr As Integer = 0 To names.Length - 1
sortKeys(ctr) = ci.GetSortKey(names(ctr), CompareOptions.IgnoreCase)
Next
' Sort array based on value of sort keys.
Array.Sort(names, sortKeys)
Console.WriteLine("Sorted array: ")
For Each name In names
Console.WriteLine(name)
Next
Console.WriteLine()
Dim namesToFind() As String = { "Paul", "PAUL", "Wilberforce" }
Console.WriteLine("Searching an array:")
For Each nameToFind In namesToFind
Dim searchKey As SortKey = ci.GetSortKey(nameToFind, CompareOptions.IgnoreCase)
Dim index As Integer = Array.FindIndex(sortKeys,
Function(x) x.Equals(searchKey))
If index >= 0 Then
Console.WriteLine("{0} found at index {1}: {2}", nameToFind,
index, names(index))
Else
Console.WriteLine("{0} not found", nameToFind)
End If
Next
End Sub
End Module
输出:
Sorted array: Adam Batholomew Benedict Clement Dalmatius Edgar Frances George Gregory Harold Ignatius John Paul Searching an array: Paul found at index 12: Paul PAUL found at index 12: Paul Wilberforce not found