0

I have a sentence about 5/6 words. I want to convert first alphabet of the sentence in uppercase and rest is in lowercase in asp.net(C#)

Current Text: I LOVE CODING

Converted Text: I love coding

Community
  • 1
  • 1

1 Answers1

0
private string Solve(string sentence)
{
    if (sentence != null && sentence.Length > 0)
    {
        return sentence[0].ToString().ToUpper() + sentence.Substring(1).ToLower();
    }
    else
    {
        return sentence;
    }
}
  • This will not uppercase a single character - e.g. "a" to "A" - you should consider doing the length check separately and appending the remaining lowercase letters if there are any. You should also consider using !string.IsNullOrWhiteSpace(sentence) as the initial test rather than sentence != null. – Rob Sep 12 '19 at 11:11