UcWords
Emulates PHPs ucwords - capitalize each word
Source
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();