本文整理汇总了C#中System.String.ToLower方法的典型用法代码示例。如果您正苦于以下问题:C# String.ToLower方法的具体用法?C# String.ToLower怎么用?C# String.ToLower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.ToLower方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
// Sample for String.ToLower(CultureInfo)
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
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;
Console.WriteLine();
Console.WriteLine("str1 = '{0}'", str1);
Console.WriteLine();
Console.WriteLine("str1 is {0} to str2.",
((0 == String.CompareOrdinal(str1, str2)) ? "equal" : "not equal"));
CodePoints("str1", str1);
CodePoints("str2", str2);
Console.WriteLine();
// str3 is a lower case copy of str2, using English-United States culture.
Console.WriteLine("str3 = Lower case copy of str2 using English-United States culture.");
str3 = str2.ToLower(new CultureInfo("en-US", false));
// str4 is a lower case copy of str2, using Turkish-Turkey culture.
Console.WriteLine("str4 = Lower case copy of str2 using Turkish-Turkey culture.");
str4 = str2.ToLower(new CultureInfo("tr-TR", false));
// Compare the code points in str3 and str4.
Console.WriteLine();
Console.WriteLine("str3 is {0} to str4.",
((0 == String.CompareOrdinal(str3, str4)) ? "equal" : "not equal"));
CodePoints("str3", str3);
CodePoints("str4", str4);
}
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();
}
}
输出:
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
示例2: Main
//引入命名空间
using System;
public class ToLowerTest {
public static void Main() {
string [] info = {"Name", "Title", "Age", "Location", "Gender"};
Console.WriteLine("The initial values in the array are:");
foreach (string s in info)
Console.WriteLine(s);
Console.WriteLine("{0}The lowercase of these values is:", Environment.NewLine);
foreach (string s in info)
Console.WriteLine(s.ToLower());
Console.WriteLine("{0}The uppercase of these values is:", Environment.NewLine);
foreach (string s in info)
Console.WriteLine(s.ToUpper());
}
}
输出:
The initial values in the array are: Name Title Age Location Gender The lowercase of these values is: name title age location gender The uppercase of these values is: NAME TITLE AGE LOCATION GENDER
示例3: String.ToLower()
//引入命名空间
using System;
class MainClass {
public static void Main() {
string str1 = "ABCDEabcde1234567890";
string strLow = str1.ToLower();
string strUp = str1.ToUpper();
Console.WriteLine("Lowercase version of str1:\n " + strLow);
Console.WriteLine("Uppercase version of str1:\n " + strUp);
}
}