C#ToLower()方法
ToLower()
C#中的方法用于返回转换为小写形式的此字符串的副本。
语法
语法如下-
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("\n\nString2 = "+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("\n\nString2 = "+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