Skip to content

Instantly share code, notes, and snippets.

@SamKr
Created March 12, 2019 10:15
Show Gist options
  • Select an option

  • Save SamKr/6e3d267f17556d6658cabf85a5a0c901 to your computer and use it in GitHub Desktop.

Select an option

Save SamKr/6e3d267f17556d6658cabf85a5a0c901 to your computer and use it in GitHub Desktop.
Change the first letter of every word into uppercase, lowercasing everything else
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