本文整理汇总了C#中System.Globalization.CompareInfo.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# CompareInfo.Compare方法的具体用法?C# CompareInfo.Compare怎么用?C# CompareInfo.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.CompareInfo
的用法示例。
在下文中一共展示了CompareInfo.Compare方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
// 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.
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "calor";
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myCompInva = 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 ) );
}
}
输出:
Comparing "calle" and "calor" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例2: Main
//引入命名空间
using System;
using System.Text;
using System.Globalization;
public sealed class App
{
static void Main(string[] args)
{
String[] sign = new String[] { "<", "=", ">" };
// The code below demonstrates how strings compare
// differently for different cultures.
String s1 = "Coté", s2 = "coté", s3 = "côte";
// Set sort order of strings for French in France.
CompareInfo ci = 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]);
}
}
输出:
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: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "My Uncle Bill's clients";
String myStr2 = "My uncle bills clients";
// Creates a CompareInfo that uses the InvariantCulture.
CompareInfo myComp = 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 | CompareOptions.IgnoreSymbols ) );
}
}
输出:
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
示例4: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "calor";
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myCompInva = 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 ) );
}
}
输出:
Comparing "lle" and "lor" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例5: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "My Uncle Bill's clients";
String myStr2 = "My uncle bills clients";
// Creates a CompareInfo that uses the InvariantCulture.
CompareInfo myComp = 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 | CompareOptions.IgnoreSymbols ) );
}
}
输出:
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
示例6: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "calor";
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myCompInva = 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 ) );
}
}
输出:
Comparing "ll" and "lo" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1
示例7: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "My Uncle Bill's clients";
String myStr2 = "My uncle bills clients";
// Creates a CompareInfo that uses the InvariantCulture.
CompareInfo myComp = 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 | CompareOptions.IgnoreSymbols ) );
}
}
输出:
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