Created
February 11, 2018 12:17
-
-
Save KristofferK/6cfd2d914c8d2cabcbe42b28faee5d75 to your computer and use it in GitHub Desktop.
Capitalizes words. "hello world" => "Hello World"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Utils | |
| { | |
| public static class Util | |
| { | |
| public static string UpperFirstChar(string s) | |
| { | |
| if (s == null) return null; | |
| if (s.Length == 1) return s.ToUpper(); | |
| if (s.Length > 1) return char.ToUpper(s[0]) + s.Substring(1); | |
| return s; | |
| } | |
| public static string UpperWords(string s) | |
| { | |
| if (s == null) return null; | |
| return s.Split(' ') | |
| .Select(e => UpperFirstChar(e)) | |
| .Aggregate((current, next) => current + " " + next); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment