Search code examples
c#stringsplit

shortest way to get first char from every word in a string


I want a shortest way to get 1st char of every word in a string in C#.

what I have done is:

string str = "This is my style";
string [] output = str.Split(' ');
foreach(string s in output)
{
   Console.Write(s[0]+" ");
}

// Output
T i m s

I want to display same output with a shortest way...

Thanks


Solution

  • string str = "This is my style"; 
    str.Split(' ').ToList().ForEach(i => Console.Write(i[0] + " "));