Candor.StringExtensions.ToSentence C# (CSharp) Method

ToSentence() public static method

Converts a string to a sentence, making word boundaries at capital letters following a lower case letter and replacing underscores with a space.
public static ToSentence ( this text ) : string
text this
return string
        public static string ToSentence(this string text)
        {
            text = text.Replace("_", " ");
            if (string.IsNullOrEmpty(text))
                return String.Empty;
            var newText = new StringBuilder(text.Length * 2);
            newText.Append(text[0]);
            for (int i = 1; i < text.Length; i++)
            {
                char prev = newText[newText.Length - 1];
                if (char.IsUpper(text[i]) && prev != ' ' && char.IsLower(prev) && !char.IsWhiteSpace(prev))
                    newText.Append(' ');
                newText.Append(text[i]);
            }
            return newText.ToString();
        }