MSDN Library
信息
您所需的主题如下所示。但此主题未包含在此库中。

String.ToUpper 方法 (CultureInfo)

2013/12/13

根据指定区域性的大小写规则返回此字符串转换为大写形式的副本。

Namespace:  System
程序集:  mscorlib(位于 mscorlib.dll 中)

public string ToUpper(
	CultureInfo culture
)

参数

culture
类型: System.Globalization.CultureInfo
一个对象,用于提供区域性特定的大小写规则。

返回值

类型: System.String
当前字符串的等效大写形式。

异常条件
ArgumentNullException

culturenull

culture 参数指定的区域性的大小写规则决定更改字符串大小写的方法。

说明注意:

此方法不修改当前实例的值。而是返回一个新字符串,其中将当前实例中的所有字符都转换为大写。

下面的代码示例将两个由小写字符组成的字符串转换为两个由大写字符组成的字符串,转换时使用“美国英语”和“土耳其土耳其语”区域性,然后对大写字符串进行比较。两个大写字符串相同,唯一区别在于:在一个字符串中每次出现的 Unicode LATIN CAPITAL LETTER I,在另一个字符串中为 LATIN CAPITAL LETTER I WITH DOT ABOVE。


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

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      String str1 = "indigo";
      String str2, str3;

      outputBlock.Text += "\n";
      outputBlock.Text += String.Format("str1 = '{0}'", str1) + "\n";

      outputBlock.Text += "str2 = Upper case copy of str1 using English-United States culture." + "\n";
      // str2 is an upper case copy of str1, using English-United States culture.
      str2 = str1.ToUpper(new CultureInfo("en-US"));

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

      // Compare the code points in str2 and str3.
      outputBlock.Text += "\n";
      outputBlock.Text += String.Format("str2 is {0} to str3.",
           ((0 == String.CompareOrdinal(str2, str3)) ? "equal" : "not equal")) + "\n";
      CodePoints(outputBlock, "str1", str1);
      CodePoints(outputBlock, "str2", str2);
      CodePoints(outputBlock, "str3", str3);
   }

   public static void CodePoints(System.Windows.Controls.TextBlock outputBlock, String title, String s)
   {
      outputBlock.Text += String.Format("{0}The code points in {1} are: {0}", "\n", title);
      foreach (ushort u in s)
         outputBlock.Text += String.Format("{0:x4} ", u);
      outputBlock.Text += "\n";
   }
}
/*
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 Phone OS

受以下版本支持: 8.0, 7.1, 7.0

Windows Phone

显示:
© 2016 Microsoft