Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将句子的第一个字母表转换为大写,其余字母表转换为小写_C#_Asp.net - Fatal编程技术网

C# 将句子的第一个字母表转换为大写,其余字母表转换为小写

C# 将句子的第一个字母表转换为大写,其余字母表转换为小写,c#,asp.net,C#,Asp.net,我有一个大约5/6个单词的句子。在asp.net(C#)中,我想将句子的第一个字母表转换为大写,其余字母表转换为小写 当前文本:我喜欢编码 转换文本:我喜欢编码 欢迎来到SO。你可以把你的代码,也不会大写一个字符-例如“A”到“A”-你应该考虑做长度检查分开,并追加剩余小写字母,如果有任何。你也应该考虑使用!string.IsNullOrWhiteSpace(句子)作为初始测试,而不是句子!=无效的 private string Solve(string sentence) { if (

我有一个大约5/6个单词的句子。在asp.net(C#)中,我想将句子的第一个字母表转换为大写,其余字母表转换为小写

当前文本:我喜欢编码

转换文本:我喜欢编码


欢迎来到SO。你可以把你的代码,也不会大写一个字符-例如“A”到“A”-你应该考虑做长度检查分开,并追加剩余小写字母,如果有任何。你也应该考虑使用!string.IsNullOrWhiteSpace(句子)作为初始测试,而不是句子!=无效的
private string Solve(string sentence)
{
    if (sentence != null && sentence.Length > 0)
    {
        return sentence[0].ToString().ToUpper() + sentence.Substring(1).ToLower();
    }
    else
    {
        return sentence;
    }
}