|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
CompareInfo.Compare, méthode (String, Int32, Int32, String, Int32, Int32)
Espace de noms : System.Globalization
Assembly : mscorlib (dans mscorlib.dll)
public virtual int Compare( string string1, int offset1, int length1, string string2, int offset2, int length2 )
Paramètres
- string1
- Type : System.String
Première chaîne à comparer.
- offset1
- Type : System.Int32
Index de base zéro du caractère de string1 au niveau duquel commencer la comparaison.
- length1
- Type : System.Int32
Nombre de caractères consécutifs dans string1 à comparer.
- string2
- Type : System.String
Deuxième chaîne à comparer.
- offset2
- Type : System.Int32
Index de base zéro du caractère de string2 au niveau duquel commencer la comparaison.
- length2
- Type : System.Int32
Nombre de caractères consécutifs dans string2 à comparer.
Valeur de retour
Type : System.Int32| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException |
Remarque |
|---|
Objet CompareInfo associé à la culture espagnole (Espagne) avec tri international Objet CompareInfo associé à la culture espagnole (Espagne) avec tri traditionnel Objet CompareInfo associé au 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.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 ) ); } } /* This code produces the following output. Comparing "ll" and "lo" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1 */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Remarque