本文整理匯總了VB.NET中System.Globalization.SortKey.Compare方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET SortKey.Compare方法的具體用法?VB.NET SortKey.Compare怎麽用?VB.NET SortKey.Compare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Globalization.SortKey
的用法示例。
在下文中一共展示了SortKey.Compare方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' This code example demonstrates the CompareInfo.Compare() and
' SortKey.Compare() methods.
Imports System.Globalization
Class Sample
Public Shared Sub Main()
Dim lowerABC As String = "abc"
Dim upperABC As String = "ABC"
Dim result As Integer = 0
' Create a CompareInfo object for the en-US culture.
Console.WriteLine(vbCrLf & _
"Create a CompareInfo object for the en-US culture..." & _
vbCrLf)
Dim cmpi As CompareInfo = CompareInfo.GetCompareInfo("en-US")
' Alternatively:
' Dim cmpi As CompareInfo = New CultureInfo("en-US").CompareInfo
' Create sort keys for lowercase and uppercase "abc", the en-US culture, and
' ignore case.
Dim sk1LowerIgnCase As SortKey = cmpi.GetSortKey(lowerABC, CompareOptions.IgnoreCase)
Dim sk2UpperIgnCase As SortKey = cmpi.GetSortKey(upperABC, CompareOptions.IgnoreCase)
' Create sort keys for lowercase and uppercase "abc", the en-US culture, and
' use case.
Dim sk1LowerUseCase As SortKey = cmpi.GetSortKey(lowerABC, CompareOptions.None)
Dim sk2UpperUseCase As SortKey = cmpi.GetSortKey(upperABC, CompareOptions.None)
' Compare lowercase and uppercase "abc", ignoring case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.IgnoreCase)
Display(result, "CompareInfo, Ignore case", lowerABC, upperABC)
' Compare lowercase and uppercase "abc", ignoring case and using SortKey.
result = SortKey.Compare(sk1LowerIgnCase, sk2UpperIgnCase)
Display(result, "SortKey, Ignore case", lowerABC, upperABC)
Console.WriteLine()
' Compare lowercase and uppercase "abc", using case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.None)
Display(result, "CompareInfo, Use case", lowerABC, upperABC)
' Compare lowercase and uppercase "abc", using case and using SortKey.
result = SortKey.Compare(sk1LowerUseCase, sk2UpperUseCase)
Display(result, "SortKey, Use case", lowerABC, upperABC)
End Sub
' Display the results of a comparison.
Private Shared Sub Display(ByVal compareResult As Integer, _
ByVal title As String, _
ByVal lower As String, _
ByVal upper As String)
Dim lessThan As String = "less than "
Dim equalTo As String = "equal to "
Dim greaterThan As String = "greater than "
Dim resultPhrase As String = Nothing
Dim format As String = "{0}:" & vbCrLf & " ""{1}"" is {2}""{3}""."
If compareResult < 0 Then
resultPhrase = lessThan
ElseIf compareResult > 0 Then
resultPhrase = greaterThan
Else
resultPhrase = equalTo
End If
Console.WriteLine(format, title, lower, resultPhrase, upper)
End Sub
End Class
輸出:
Create a CompareInfo object for the en-US culture... CompareInfo, Ignore case: "abc" is equal to "ABC". SortKey, Ignore case: "abc" is equal to "ABC". CompareInfo, Use case: "abc" is less than "ABC". SortKey, Use case: "abc" is less than "ABC".