本文整理汇总了VB.NET中System.Globalization.CompareInfo.Compare方法的典型用法代码示例。如果您正苦于以下问题:VB.NET CompareInfo.Compare方法的具体用法?VB.NET CompareInfo.Compare怎么用?VB.NET CompareInfo.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.CompareInfo
的用法示例。
在下文中一共展示了CompareInfo.Compare方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesCompareInfo
' The following code example compares two strings using the different CompareInfo instances:
' a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
' a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
' a CompareInfo instance associated with the InvariantCulture.
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "calor"
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)
' Uses the CompareInfo property of the InvariantCulture.
Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myCompIntl.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1, myStr2)
Console.WriteLine(" With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, myStr2))
End Sub
End Class
输出:
Comparing "calle" and "calor" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例2: Main
' 导入命名空间
Imports System.Text
Imports System.Globalization
NotInheritable Public Class App
Shared Sub Main(ByVal args() As String)
Dim sign() As String = {"<", "=", ">"}
' The code below demonstrates how strings compare
' differently for different cultures.
Dim s1 As String = "Coté"
Dim s2 As String = "coté"
Dim s3 As String = "côte"
' Set sort order of strings for French in France.
Dim ci As CompareInfo = New CultureInfo("fr-FR").CompareInfo
Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID)
' Display the result using fr-FR Compare of Coté = coté.
Console.WriteLine("fr-FR Compare: {0} {2} {1}", _
s1, s2, sign((ci.Compare(s1, s2, CompareOptions.IgnoreCase) + 1)))
' Display the result using fr-FR Compare of coté > côte.
Console.WriteLine("fr-FR Compare: {0} {2} {1}", _
s2, s3, sign((ci.Compare(s2, s3, CompareOptions.None) + 1)))
' Set sort order of strings for Japanese as spoken in Japan.
ci = New CultureInfo("ja-JP").CompareInfo
Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID)
' Display the result using ja-JP Compare of coté < côte.
Console.WriteLine("ja-JP Compare: {0} {2} {1}", _
s2, s3, sign((ci.Compare(s2, s3) + 1)))
End Sub
End Class
输出:
The LCID for fr-FR is 1036. fr-FR Compare: Coté = coté fr-FR Compare: coté > côte The LCID for ja-JP is 1041. ja-JP Compare: coté < côte
示例3: Example
' 导入命名空间
Imports System.Globalization
Module Example
Public Sub Main()
Dim ci As CompareInfo = CultureInfo.CurrentCulture.CompareInfo
Dim s1 As String = "ani" + ChrW(&h00AD) + "mal"
Dim s2 As String = "animal"
Console.WriteLine("Comparison of '{0}' and '{1}': {2}",
s1, s2, ci.Compare(s1, s2))
End Sub
End Module
输出:
Comparison of 'ani-mal' and 'animal': 0
示例4: SamplesCompareInfo
' 导入命名空间
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "My Uncle Bill's clients"
Dim myStr2 As [String] = "My uncle bills clients"
' Creates a CompareInfo that uses the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myComp.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1, myStr2)
Console.WriteLine(" With no CompareOptions : {0}", myComp.Compare(myStr1, myStr2))
Console.WriteLine(" With None : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.None))
Console.WriteLine(" With Ordinal : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.Ordinal))
Console.WriteLine(" With StringSort : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.StringSort))
Console.WriteLine(" With IgnoreCase : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.IgnoreCase))
Console.WriteLine(" With IgnoreSymbols : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.IgnoreSymbols))
Console.WriteLine(" With IgnoreCase and IgnoreSymbols : {0}", myComp.Compare(myStr1, myStr2, CompareOptions.IgnoreCase Or CompareOptions.IgnoreSymbols))
End Sub
End Class
输出:
Comparing "My Uncle Bill's clients" and "My uncle bills clients" With no CompareOptions : 1 With None : 1 With Ordinal : -32 With StringSort : -1 With IgnoreCase : 1 With IgnoreSymbols : 1 With IgnoreCase and IgnoreSymbols : 0
示例5: SamplesCompareInfo
' 导入命名空间
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "calor"
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)
' Uses the CompareInfo property of the InvariantCulture.
Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myCompIntl.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1.Substring(2), myStr2.Substring(2))
Console.WriteLine(" With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, 2, myStr2, 2))
Console.WriteLine(" With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, 2, myStr2, 2))
Console.WriteLine(" With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, 2, myStr2, 2))
End Sub
End Class
输出:
Comparing "lle" and "lor" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例6: SamplesCompareInfo
' 导入命名空间
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "My Uncle Bill's clients"
Dim myStr2 As [String] = "My uncle bills clients"
' Creates a CompareInfo that uses the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myComp.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1.Substring(10), myStr2.Substring(10))
Console.WriteLine(" With no CompareOptions : {0}", myComp.Compare(myStr1, 10, myStr2, 10))
Console.WriteLine(" With None : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.None))
Console.WriteLine(" With Ordinal : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.Ordinal))
Console.WriteLine(" With StringSort : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.StringSort))
Console.WriteLine(" With IgnoreCase : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.IgnoreCase))
Console.WriteLine(" With IgnoreSymbols : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.IgnoreSymbols))
Console.WriteLine(" With IgnoreCase and IgnoreSymbols : {0}", myComp.Compare(myStr1, 10, myStr2, 10, CompareOptions.IgnoreCase Or CompareOptions.IgnoreSymbols))
End Sub
End Class
输出:
Comparing "ill's clients" and "ills clients" With no CompareOptions : 1 With None : 1 With Ordinal : -76 With StringSort : -1 With IgnoreCase : 1 With IgnoreSymbols : 0 With IgnoreCase and IgnoreSymbols : 0
示例7: SamplesCompareInfo
' 导入命名空间
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "calor"
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)
' Uses the CompareInfo property of the InvariantCulture.
Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myCompIntl.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1.Substring(2, 2), myStr2.Substring(2, 2))
Console.WriteLine(" With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, 2, 2, myStr2, 2, 2))
Console.WriteLine(" With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, 2, 2, myStr2, 2, 2))
Console.WriteLine(" With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, 2, 2, myStr2, 2, 2))
End Sub
End Class
输出:
Comparing "ll" and "lo" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例8: SamplesCompareInfo
' 导入命名空间
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "My Uncle Bill's clients"
Dim myStr2 As [String] = "My uncle bills clients"
' Creates a CompareInfo that uses the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myComp.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1.Substring(3, 10), myStr2.Substring(3, 10))
Console.WriteLine(" With no CompareOptions : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10))
Console.WriteLine(" With None : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.None))
Console.WriteLine(" With Ordinal : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.Ordinal))
Console.WriteLine(" With StringSort : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.StringSort))
Console.WriteLine(" With IgnoreCase : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.IgnoreCase))
Console.WriteLine(" With IgnoreSymbols : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.IgnoreSymbols))
Console.WriteLine(" With IgnoreCase and IgnoreSymbols : {0}", myComp.Compare(myStr1, 3, 10, myStr2, 3, 10, CompareOptions.IgnoreCase Or CompareOptions.IgnoreSymbols))
End Sub
End Class
输出:
Comparing "Uncle Bill" and "uncle bill" With no CompareOptions : 1 With None : 1 With Ordinal : -32 With StringSort : 1 With IgnoreCase : 0 With IgnoreSymbols : 1 With IgnoreCase and IgnoreSymbols : 0