C# ToLower() 方法


C# 中的 ToLower() 方法用于返回此字符串的副本,该副本已转换为小写。

语法

语法如下 -

public string ToLower ();

示例

我们现在来看一个示例 -

 在线演示

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "WELCOME!";
      string str2 = "Thisisit!";
      char[] arr1 = str1.ToCharArray(3,2);
      char[] arr2 = str2.ToCharArray(2,2);
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToLower = "+str1.ToLower());
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(4, 4));
      Console.Write("Character array...String1 =");
      for (int i = 0; i < arr1.Length; i++)
         Console.Write(" " + arr1[i]);
      Console.WriteLine("

String2 = "+str2);       Console.WriteLine("String2 ToLower = "+str2.ToLower());       Console.WriteLine("String2 Substring from index2 = " + str2.Substring(0, 5));       Console.Write("Character array...String2 =");       for (int i = 0; i < arr2.Length; i++)          Console.Write(" " + arr2[i]);    } }

输出

String1 = WELCOME!
String1 ToLower = welcome!
String1 Substring from index4 = OME!
Character array...String1 = C O
String2 = Thisisit!
String2 ToLower = thisisit!
String2 Substring from index2 = Thisi
Character array...String2 = i s

示例

我们现在来看另一个示例 -

 在线演示

using System;
using System.Globalization;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "ABCD!";
      string str2 = "@#$PQRSTUV!";
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToLower = "+str1.ToLower(new CultureInfo("en-US", false)));
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(2, 2));
      Console.WriteLine("

String2 = "+str2);       Console.WriteLine("String2 ToLower = "+str2.ToLower(new CultureInfo("en-US", false)));       Console.WriteLine("String2 Substring from index2 = " + str2.Substring(0, 5));    } }

输出

String1 = ABCD!
String1 ToLower = abcd!
String1 Substring from index4 = CD
String2 = @#$PQRSTUV!
String2 ToLower = @#$pqrstuv!
String2 Substring from index2 = @#$PQ

更新于: 03-12-2019

274 次浏览

开启你的 职业生涯

通过完成这项课程获得认证

开始
广告