Tuesday, 4 December 2012

c# - Make first letter of each word upper case

c# - Make first letter of each word upper case


              System.Text.StringBuilder upperResult = new StringBuilder();
//it makes first char of each word to upper,result added to stringBuilder.              
  String mkfu = "Initiating the debate, Leader of the Opposition Sushma Swaraj contended that Prime Minister Manmohan Singh, as Leader of the Opposition in the Rajya Sabha in 2002";
                String[] words = mkfu.Split(' ');
                foreach (String word in words)
                {
                    upperResult.Append(word[0].ToString().ToUpper() + word.Substring(1));
                    upperResult.AppendLine();
                }

                Console.WriteLine(upperResult.ToString());

Output


Initiating
The
Debate,
Leader
Of
The
Opposition
Sushma
Swaraj
Contended
That
Prime
Minister
Manmohan
Singh,
As
Leader
Of
The
Opposition
In
The
Rajya
Sabha
In
2002