String.ToUpperInvariant Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une copie de cet String objet converti en majuscules à l’aide des règles de casse de la culture invariante.
public:
System::String ^ ToUpperInvariant();
public string ToUpperInvariant();
member this.ToUpperInvariant : unit -> string
Public Function ToUpperInvariant () As String
Retours
Équivalent en majuscules de la chaîne actuelle.
Exemples
L’exemple suivant définit un tableau de chaînes qui contient un mot unique dans un certain nombre de langues. La ToUpperInvariant méthode est utilisée pour remplir les éléments d’un tableau parallèle avec la version sans respect de la casse de chaque mot. La Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>) méthode est utilisée pour trier le tableau sensible à la casse en fonction de l’ordre des éléments dans le tableau en majuscules pour s’assurer que les éléments apparaissent dans le même ordre, quel que soit le langage.
using System;
using System.IO;
public class Example
{
public static void Main()
{
string[] words = { "Tuesday", "Salı", "Вторник", "Mardi",
"Τρίτη", "Martes", "יום שלישי",
"الثلاثاء", "วันอังคาร" };
StreamWriter sw = new StreamWriter(@".\output.txt");
// Display array in unsorted order.
foreach (string word in words)
sw.WriteLine(word);
sw.WriteLine();
// Create parallel array of words by calling ToUpperInvariant.
string[] upperWords = new string[words.Length];
for (int ctr = words.GetLowerBound(0); ctr <= words.GetUpperBound(0); ctr++)
upperWords[ctr] = words[ctr].ToUpperInvariant();
// Sort the words array based on the order of upperWords.
Array.Sort(upperWords, words, StringComparer.InvariantCulture);
// Display the sorted array.
foreach (string word in words)
sw.WriteLine(word);
sw.Close();
}
}
// The example produces the following output:
// Tuesday
// Salı
// Вторник
// Mardi
// Τρίτη
// Martes
// יום שלישי
// الثلاثاء
// วันอังคาร
//
// Mardi
// Martes
// Salı
// Tuesday
// Τρίτη
// Вторник
// יום שלישי
// الثلاثاء
// วันอังคาร
open System
open System.IO
do
let words =
[| "Tuesday"; "Salı"; "Вторник"; "Mardi"
"Τρίτη"; "Martes"; "יום שלישי"
"الثلاثاء"; "วันอังคาร" |]
use sw = new StreamWriter(@".\output.txt")
// Display array in unsorted order.
for word in words do
sw.WriteLine word
sw.WriteLine()
// Create parallel array of words by calling ToUpperInvariant.
let upperWords = words |> Array.map (fun x -> x.ToUpperInvariant())
// Sort the words array based on the order of upperWords.
Array.Sort(upperWords, words, StringComparer.InvariantCulture)
// Display the sorted array.
for word in words do
sw.WriteLine word
sw.Close()
// The example produces the following output:
// Tuesday
// Salı
// Вторник
// Mardi
// Τρίτη
// Martes
// יום שלישי
// الثلاثاء
// วันอังคาร
//
// Mardi
// Martes
// Salı
// Tuesday
// Τρίτη
// Вторник
// יום שלישי
// الثلاثاء
// วันอังคาร
Imports System.IO
Module Example
Public Sub Main()
Dim words() As String = { "Tuesday", "Salı", "Вторник", "Mardi", _
"Τρίτη", "Martes", "יום שלישי", _
"الثلاثاء", "วันอังคาร" }
Dim sw As New StreamWriter(".\output.txt")
' Display array in unsorted order.
For Each word As String In words
sw.WriteLine(word)
Next
sw.WriteLine()
' Create parallel array of words by calling ToUpperInvariant.
Dim upperWords(words.Length - 1) As String
For ctr As Integer = words.GetLowerBound(0) To words.GetUpperBound(0)
upperWords(ctr) = words(ctr).ToUpperInvariant()
Next
' Sort the words array based on the order of upperWords.
Array.Sort(upperWords, words, StringComparer.InvariantCulture)
' Display the sorted array.
For Each word As String In words
sw.WriteLine(word)
Next
sw.Close()
End Sub
End Module
' The example produces the following output:
' Tuesday
' Salı
' Вторник
' Mardi
' Τρίτη
' Martes
' יום שלישי
' الثلاثاء
' วันอังคาร
'
' Mardi
' Martes
' Salı
' Tuesday
' Τρίτη
' Вторник
' יום שלישי
' الثلاثاء
' วันอังคาร
Remarques
La culture invariante représente une culture qui ne dépend pas de la culture. Il est associé à la langue anglaise, mais pas à un pays ou une région spécifique. Pour plus d’informations, consultez la propriété CultureInfo.InvariantCulture.
Si votre application dépend du cas d’une chaîne qui change de manière prévisible qui n’est pas affectée par la culture actuelle, utilisez la ToUpperInvariant méthode. La ToUpperInvariant méthode est équivalente à ToUpper(CultureInfo.InvariantCulture). La méthode est recommandée lorsqu’une collection de chaînes doit apparaître dans un ordre prévisible dans un contrôle d’interface utilisateur.
Note
Cette méthode ne modifie pas la valeur de l’instance actuelle. Au lieu de cela, elle retourne une nouvelle chaîne dans laquelle tous les caractères de l’instance actuelle sont convertis en majuscules.
Si vous avez besoin de la version minuscule ou majuscule d’un identificateur de système d’exploitation, tel qu’un nom de fichier, un canal nommé ou une clé de Registre, utilisez les méthodes ou ToUpperInvariant les ToLowerInvariant méthodes.