Skip to content

Instantly share code, notes, and snippets.

@KristofferK
Created February 11, 2018 12:17
Show Gist options
  • Select an option

  • Save KristofferK/6cfd2d914c8d2cabcbe42b28faee5d75 to your computer and use it in GitHub Desktop.

Select an option

Save KristofferK/6cfd2d914c8d2cabcbe42b28faee5d75 to your computer and use it in GitHub Desktop.
Capitalizes words. "hello world" => "Hello World"
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