Just to round things out, an alternative solution using Linq with extension methods.
public static string ToSentenceCase(this string value)
{
string[] spacedWords
= ((IEnumerable<char>)value).Skip(1)
.Select(c => c == char.ToUpper(c)
? " " + char.ToLower(c).ToString()
: c.ToString()).ToArray();
string result = value.Substring(0, 1)
+ (String.Join("", spacedWords)).Trim();
return result;
}
Returns:
"Main page background color"
public static string ToTitleCase(this string value)
{
string[] spacedWords
= ((IEnumerable<char>)value)
.Select(c => c == char.ToUpper(c)
? " " + c.ToString()
: c.ToString()).ToArray();
return (String.Join("", spacedWords)).Trim();
}
Returns:
"Main Page Background Color"