Created
March 12, 2019 10:15
-
-
Save SamKr/6e3d267f17556d6658cabf85a5a0c901 to your computer and use it in GitHub Desktop.
Change the first letter of every word into uppercase, lowercasing everything else
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
| internal static string UppercaseWords(string value) | |
| { | |
| if (string.IsNullOrEmpty(value)) return value; | |
| value = value.ToLower(); | |
| var array = value.ToCharArray(); | |
| if (array.Length >= 1) | |
| { | |
| if (char.IsLower(array[0])) | |
| { | |
| array[0] = char.ToUpper(array[0]); | |
| } | |
| } | |
| for (var i = 1; i < array.Length; i++) | |
| { | |
| if (array[i - 1] != ' ') continue; | |
| if (char.IsLower(array[i])) array[i] = char.ToUpper(array[i]); | |
| } | |
| return new string(array); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment