温馨提示×

C#中如何实现字符串的大小写转换

c#
小樊
152
2024-08-22 00:33:27
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C#中,可以使用ToLower()方法将字符串转换为小写,使用ToUpper()方法将字符串转换为大写。示例如下:

string str = "Hello, World!";
string upperStr = str.ToUpper();
string lowerStr = str.ToLower();

Console.WriteLine("原始字符串:" + str);
Console.WriteLine("转换为大写:" + upperStr);
Console.WriteLine("转换为小写:" + lowerStr);

输出结果为:

原始字符串:Hello, World!
转换为大写:HELLO, WORLD!
转换为小写:hello, world!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:C#中字符串的大小写转换技巧

0