Candor.StringExtensions.GenerateTeaser C# (CSharp) Method

GenerateTeaser() public static method

Generates a teaser phrase from any body of text. If the text is shortened from the specified max length, an ellipsis ("...") is added.
public static GenerateTeaser ( this text, Int32 maxSentences, Int32 maxCharacters ) : string
text this The original body text.
maxSentences System.Int32 The max number of sentences from the original text.
maxCharacters System.Int32 The maximum total characters to return.
return string
        public static string GenerateTeaser(this string text, Int32 maxSentences, Int32 maxCharacters)
        {
            var sentences = text.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries)
                .Where(x => !string.IsNullOrWhiteSpace(x)).Take(maxSentences);
            var combined = string.Join(". ", sentences);
            return combined.Length <= maxCharacters
                ? combined
                : combined.Substring(0, maxCharacters - 3) + "...";
        }