Développer Réduire
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

String.ToUpperInvariant, méthode

Mise à jour : novembre 2007

Retourne une copie de cet objet String converti en majuscules à l'aide des règles de la culture dite indifférente se rapportant à la casse.

Espace de noms :  System
Assembly :  mscorlib (dans mscorlib.dll)
public string ToUpperInvariant()
public String ToUpperInvariant()
public function ToUpperInvariant() : String

Valeur de retour

Type : System.String
Objet String en majuscules.

Si votre application dépend de la casse d'une chaîne qui se modifie d'une façon prévisible non affectée par la culture en cours, utilisez la méthode ToUpperInvariant. La méthode ToUpperInvariant est équivalente à ToUpper(CultureInfo.InvariantCulture).

Considérations sur la sécurité

Si vous avez besoin de la version en minuscules ou en majuscules d'un identificateur de système d'exploitation, par exemple un nom de fichier, un canal nommé ou une clé de Registre, utilisez les méthodes ToLowerInvariant ou ToUpperInvariant.

L'exemple de code suivant convertit une chaîne de minuscules en deux chaînes de majuscules à l'aide des cultures Anglais-États-Unis et Turc-Turquie, puis compare les chaînes en majuscules. Les chaînes en majuscules sont identiques si ce n'est que pour chaque occurrence de la LETTRE MAJUSCULE LATINE Unicode I dans une chaîne, l'autre chaîne contient la LETTRE MAJUSCULE LATINE I surmontée d'un point.

// Sample for String.ToUpper(CultureInfo)
using System;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
    String str1 = "indigo";
    String str2, str3;

    Console.WriteLine();
    Console.WriteLine("str1 = '{0}'", str1);

    Console.WriteLine("str2 = Upper case copy of str1 using English-United States culture.");
    // str2 is an upper case copy of str1, using English-United States culture.
    str2 = str1.ToUpper(new CultureInfo("en-US", false));

    // str3 is an upper case copy of str1, using Turkish-Turkey culture.
    Console.WriteLine("str3 = Upper case copy of str1 using Turkish-Turkey culture.");
    str3 = str1.ToUpper(new CultureInfo("tr-TR", false));

    // Compare the code points in str2 and str3.
    Console.WriteLine();
    Console.WriteLine("str2 is {0} to str3.", 
         ((0 == String.CompareOrdinal(str2, str3)) ? "equal" : "not equal"));
    CodePoints("str1", str1);
    CodePoints("str2", str2);
    CodePoints("str3", str3);
    }

    public static void CodePoints(String title, String s)
    {
    Console.Write("{0}The code points in {1} are: {0}", Environment.NewLine, title);
    foreach (ushort u in s)
      Console.Write("{0:x4} ", u);
    Console.WriteLine();
    }
}
/*
This example produces the following results:

str1 = 'indigo'
str2 = Upper case copy of str1 using English-United States culture.
str3 = Upper case copy of str1 using Turkish-Turkey culture.

str2 is not equal to str3.

The code points in str1 are:
0069 006e 0064 0069 0067 006f

The code points in str2 are:
0049 004e 0044 0049 0047 004f

The code points in str3 are:
0130 004e 0044 0130 0047 004f
*/


// Sample for String.ToUpper(CultureInfo)
import System.*;
import System.Globalization.*;

class Sample
{
    public static void main(String[] args)
    {
        String str1 = "indigo";
        String str2, str3;

        Console.WriteLine();
        Console.WriteLine("str1 = '{0}'", str1);

        Console.WriteLine("str2 = Upper case copy of str1 using English-"
            + "United States culture.");

        // str2 is an upper case copy of str1, using English-United States 
        // culture.
        str2 = str1.ToUpper(new CultureInfo("en-US", false));

        // str3 is an upper case copy of str1, using Turkish-Turkey culture.
        Console.WriteLine("str3 = Upper case copy of str1 using Turkish-"
            + "Turkey culture.");
        str3 = str1.ToUpper(new CultureInfo("tr-TR", false));

        // Compare the code points in str2 and str3.
        Console.WriteLine();
        Console.WriteLine("str2 is {0} to str3.", 
            (0 == String.CompareOrdinal(str2, str3)) ? "equal" : "not equal");
        CodePoints("str1", str1);
        CodePoints("str2", str2);
        CodePoints("str3", str3);
    } //main

    public static void CodePoints(String title, String s)
    {
        Console.Write("{0}The code points in {1} are: {0}", 
            Environment.get_NewLine(), title);
        for (int iCtr = 0; iCtr < s.get_Length(); iCtr++) {
            UInt16 u = (UInt16)s.charAt(iCtr);
            Console.Write("{0:x4} ", u);
        }
        Console.WriteLine();
    } //CodePoints
} //Sample
/*
This example produces the following results:

str1 = 'indigo'
str2 = Upper case copy of str1 using English-United States culture.
str3 = Upper case copy of str1 using Turkish-Turkey culture.

str2 is not equal to str3.

The code points in str1 are:
0069 006e 0064 0069 0067 006f

The code points in str2 are:
0049 004e 0044 0049 0047 004f

The code points in str3 are:
0130 004e 0044 0130 0047 004f
*/


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.