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
}
}

浙公网安备 33010602011771号