本文整理汇总了VB.NET中System.Globalization.CompareOptions枚举的典型用法代码示例。如果您正苦于以下问题:VB.NET CompareOptions枚举的具体用法?VB.NET CompareOptions怎么用?VB.NET CompareOptions使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了CompareOptions枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SamplesCompareOptions
' 导入命名空间
Imports System.Collections
Imports System.Globalization
Public Class SamplesCompareOptions
Private Class MyStringComparer
Implements IComparer
Private myComp As CompareInfo
Private myOptions As CompareOptions = CompareOptions.None
' Constructs a comparer using the specified CompareOptions.
Public Sub New(cmpi As CompareInfo, options As CompareOptions)
myComp = cmpi
Me.myOptions = options
End Sub
' Compares strings with the CompareOptions specified in the constructor.
Public Function Compare(a As [Object], b As [Object]) As Integer Implements IComparer.Compare
If a = b Then
Return 0
End If
If a Is Nothing Then
Return - 1
End If
If b Is Nothing Then
Return 1
End If
Dim sa As [String] = a
Dim sb As [String] = b
If Not (sa Is Nothing) And Not (sb Is Nothing) Then
Return myComp.Compare(sa, sb, myOptions)
End If
Throw New ArgumentException("a and b should be strings.")
End Function 'Compare
End Class
Public Shared Sub Main()
' Creates and initializes an array of strings to sort.
Dim myArr() As [String] = {"cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op"}
Console.WriteLine()
Console.WriteLine("Initially,")
Dim myStr As [String]
For Each myStr In myArr
Console.WriteLine(myStr)
Next myStr
' Creates and initializes a Comparer to use.
'CultureInfo myCI = new CultureInfo( "en-US", false );
Dim myComp As New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.None)
' Sorts the array without StringSort.
Array.Sort(myArr, myComp)
Console.WriteLine()
Console.WriteLine("After sorting without CompareOptions.StringSort:")
For Each myStr In myArr
Console.WriteLine(myStr)
Next myStr
' Sorts the array with StringSort.
myComp = New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.StringSort)
Array.Sort(myArr, myComp)
Console.WriteLine()
Console.WriteLine("After sorting with CompareOptions.StringSort:")
For Each myStr In myArr
Console.WriteLine(myStr)
Next myStr
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Globalization,代码行数:77,代码来源:CompareOptions 输出:
Initially,
cant
bill's
coop
cannot
billet
can't
con
bills
co-op
After sorting without CompareOptions.StringSort:
billet
bills
bill's
cannot
cant
can't
con
coop
co-op
After sorting with CompareOptions.StringSort:
bill's
billet
bills
can't
cannot
cant
co-op
con
coop
注:本文中的System.Globalization.CompareOptions枚举示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论