ToFirstAll
public static string ToFirstAll(this string input, bool switcher) { return new string(input.Split(' '). Select(n => switcher ? (n.ToArray().First().ToString().ToUpper() + n.Substring(1, n.Length - 1)) : (n.ToArray().First().ToString().ToLower() + n.Substring(1, n.Length - 1))). Aggregate((a, b) => a + ' ' + b).ToArray()).TrimEnd(' '); }Example:
string result_string = "hello world!".ToFirstAll(true); MessageBox.Show(result_string);
Description
This method makes the caps for all words in a string
Details
- Author: Denis Stoyanov
- Submitted on: 10/25/2010 8:23:20 PM
- Language: C#
- Type: System.String
- Views: 1817
Double click on the code to select all.