Question : Get first letter of each word in a phrase

Hello Everybody!

I need to get the first letter of each word in a phrase. Any Idea on how to achieve it?

Example:
string str = "The food was good";
string firstLetter = "TFWG";

I use C#
.NET Framework 3.5 SP1 + Chart Controls
Visual Studio 2008

Answer : Get first letter of each word in a phrase

There is one more flaw in the code. If you have spaces at the beginning or at the end - you will have an exeception as at least one of entries will be an empty string...

See the solution
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
        private void button1_Click(object sender, EventArgs e)
        {
            string s = " abcdef asdf ga3dsf fjaf ";
            string firstletters = "";
            foreach (string c in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                firstletters += c[0];
            }
            firstletters = firstletters.ToUpper();
            MessageBox.Show("'" + firstletters + "'");
        }
Random Solutions  
 
programming4us programming4us