UcWords

 public static StringBuilder UcWords(this string theString)
        {
            StringBuilder output = new StringBuilder();
            string[] pieces = theString.Split(' ');
            foreach (string piece in pieces)
            {
                char[] theChars = piece.ToCharArray();
                theChars[0] = char.ToUpper(theChars[0]);
                output.Append(' ');
                output.Append(new string(theChars));
            }

            return output;

        }
Example:
"a sentence of words".UcWords();

string str = "some words to capitalize";
str.UcWords();

Description

Emulates PHPs ucwords - capitalize each word

Details

Double click on the code to select all.

 

;