本文整理匯總了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