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
- Author: Stuart Sillitoe
- Submitted on: 1-6-2016 12:57:48
- Language: C#
- Type: String
- Views: 2509
Double click on the code to select all.