Imports System
Imports System.Collections
Imports System.Globalization
Public Class SamplesCompareOptions
Private Class MyStringComparer
Implements IComparer
Private myComp As CompareInfo
Private myOptions As CompareOptions = CompareOptions.None
Public Sub New(cmpi As CompareInfo, options As CompareOptions)
myComp = cmpi
Me.myOptions = options
End Sub 'New
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 'MyStringComparer
Public Shared Sub Main()
Dim myArr() As [String] = {"this", "is", "a", "tes", "This", "Is", "a", "Test", "."}
Dim myStr As [String]
Dim myComp As New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.None)
Array.Sort(myArr, myComp)
For Each myStr In myArr
Console.WriteLine(myStr)
Next myStr
myComp = New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.StringSort)
Array.Sort(myArr, myComp)
For Each myStr In myArr
Console.WriteLine(myStr)
Next myStr
End Sub
End Class