Title case sentence

I’m having a hard time figuring out how to capitalize the first letter of the first word in a sentence. Instead of “sEe me rUn” you get “See me run” as the output.

Hello, @jeanlaurore101.

It looks to me like you should be able to just add .ToLower() to the end of userInput.Substring(1). I’m not sure that’s what you’re after, but it would produce output like so:

    static void Main(string[] args)
      string userInput = "helLO WoRLd.";
      //Output: helLO WoRLd.
      userInput = Char.ToUpper(userInput[0]) + userInput.Substring(1).ToLower();
      //Output: Hello world.

Your code already capitalized the first letter of the sentence. Adding .ToLower() to the end of the referenced expression converts all of the letters in the Substring to lower case.

Oh wow! I was missing .ToLower()

Thanks you a life saver!

1 Like

You’re welcome! Happy coding!

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.