C#将字符串单词首字母转大写

使用System.Globalization命名空间下的TextInfo类的ToTitleCase方法将字符串中的单词首字母转换为大写。

using System;
using System.Globalization;
 
class Program
{
    static void Main()
    {
        string input = "hello world";
        string result = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());
        Console.WriteLine(result); // 输出: Hello World
    }
}
posted @ 2024-04-08 22:29  小辫子啦啦啦  阅读(137)  评论(0编辑  收藏  举报