导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

String.ToLower 方法 (CultureInfo)

2013/12/13

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

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

public string ToLower(
	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.ToLower(CultureInfo)

using System;
using System.Globalization;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      String str1 = "INDIGO";
      // str2 = str1, except each 'I' is '\u0130' (Unicode LATIN CAPITAL I WITH DOT ABOVE).
      String str2 = new String(new Char[] { '\u0130', 'N', 'D', '\u0130', 'G', 'O' });
      String str3, str4;

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

      outputBlock.Text += "\n";
      outputBlock.Text += String.Format("str1 is {0} to str2.",
           ((0 == String.CompareOrdinal(str1, str2)) ? "equal" : "not equal")) + "\n";
      CodePoints(outputBlock, "str1", str1);
      CodePoints(outputBlock, "str2", str2);

      outputBlock.Text += "\n";
      // str3 is a lower case copy of str2, using English-United States culture.
      outputBlock.Text += "str3 = Lower case copy of str2 using English-United States culture." + "\n";
      str3 = str2.ToLower(new CultureInfo("en-US"));

      // str4 is a lower case copy of str2, using Turkish-Turkey culture.
      outputBlock.Text += "str4 = Lower case copy of str2 using Turkish-Turkey culture." + "\n";
      str4 = str2.ToLower(new CultureInfo("tr-TR"));

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

   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'

str1 is not equal to str2.

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

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

str3 = Lower case copy of str2 using English-United States culture.
str4 = Lower case copy of str2 using Turkish-Turkey culture.

str3 is equal to str4.

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

The code points in str4 are:
0069 006e 0064 0069 0067 006f
*/


Windows Phone OS

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

Windows Phone

显示:
© 2015 Microsoft