Exporter (0) Imprimer
Développer tout

TextInfo.ToUpper Method (String)

Converts the specified string to uppercase.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

[SecuritySafeCriticalAttribute]
public virtual string ToUpper(
	string str
)

Parameters

str
Type: System.String
The string to convert to uppercase.

Return Value

Type: System.String
The specified string converted to uppercase.

ExceptionCondition
ArgumentNullException

str is null.

The returned string might differ in length from the input string. For more information on casing, refer to the Unicode standard on the Unicode Web site. The current implementation preserves the length of the string. However, this behavior is not guaranteed and could change in future implementations.

Casing semantics depend on the culture in use. For the invariant culture, the casing semantics are not culture-sensitive. For a specific culture, the casing semantics are sensitive to that culture.

If a security decision depends on a string comparison or a case-change operation, the application should use the InvariantCulture to ensure that the behavior is consistent regardless of the culture settings of the system. However, the invariant culture must be used only by processes that require culture-independent results, such as system services. Otherwise, it produces results that might be linguistically incorrect or culturally inappropriate.

For more information on cultures, see CultureInfo.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: The .NET Compact Framework uses native Windows CE functions to change characters to upper or lower case. Windows CE does not provide changing the case of surrogate pairs, so this capability is not supported in the .NET Compact Framework.

The following code example changes the casing of a string based on the "en-US" culture.


using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Defines the string with mixed casing.
      string myString = "wAr aNd pEaCe";

      // Creates a TextInfo based on the "en-US" culture.
      TextInfo myTI = new CultureInfo("en-US").TextInfo;

      // Changes a string to lowercase.
      outputBlock.Text += String.Format("\"{0}\" to lowercase: {1}", myString, myTI.ToLower(myString)) + "\n";

      // Changes a string to uppercase.
      outputBlock.Text += String.Format("\"{0}\" to uppercase: {1}", myString, myTI.ToUpper(myString)) + "\n";
   }
}
/*
This example produces the following output.
      "wAr aNd pEaCe" to lowercase: war and peace
      "wAr aNd pEaCe" to uppercase: WAR AND PEACE
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Ajouts de la communauté

AJOUTER
Microsoft réalise une enquête en ligne pour recueillir votre opinion sur le site Web de MSDN. Si vous choisissez d’y participer, cette enquête en ligne vous sera présentée lorsque vous quitterez le site Web de MSDN.

Si vous souhaitez y participer,
Afficher:
© 2014 Microsoft