-3

I have a string say "my name is john". Now I want to convert this string to "My Name Is John". how would I do that? I am using C# language. I am new to C# and don't have much idea on string manipulation.

I have tried this code

string functionName = "my name is john";
var dam = Char.ToUpperInvariant(functionName[0]) + functionName.Substring(1);

the output is "My name is john". I want "My Name Is John".

user823959
  • 782
  • 2
  • 9
  • 30
ninja
  • 21
  • 1
  • 4
  • 4
    you'll need to show what you've attempted and explain exactly what didn't work when you tried this. – JSteward Mar 02 '20 at 21:43
  • I have added some codes as well. it will be great if anyone can help me. – ninja Mar 02 '20 at 21:51
  • [How to capitalize the first character of each word, or the first character of a whole string, with C#?](https://stackoverflow.com/questions/913090/how-to-capitalize-the-first-character-of-each-word-or-the-first-character-of-a) – Nathan Cooper Mar 03 '20 at 11:41

1 Answers1

0

use this :

    string UpperFirstWords(string input)
    {
        string[] list = input.Split(' ');
        string[] output=list.Select(x => x = x[0].ToString().ToUpper() + x.Substring(1)).ToArray<string>();
        return string.Join(" ", output);
    }
        string mystr = "my name is john";
        string outp = UpperFirstWords(mystr);

after running , the outp value is : My Name Is John

ben
  • 740
  • 7
  • 16