/ Published in: C#
URL: http://www.mikesdotnetting.com/Article/137/Displaying-The-First-n-Characters-Of-Text
Returns part of a string up to the specified number of characters, while maintaining full words.
Expand |
Embed | Plain Text
/// <summary> /// Returns part of a string up to the specified number of characters, while maintaining full words /// <para>http://www.mikesdotnetting.com/Article/137/Displaying-The-First-n-Characters-Of-Text</para> /// </summary> /// <param name="s"></param> /// <param name="length">Maximum characters to be returned</param> /// <returns>String</returns> public static string Chop(this string s, int length) { if (String.IsNullOrEmpty(s)) { } foreach (var word in words.Where(word => (sb.ToString().Length + word.Length) <= length)) { sb.Append(word + " "); } return sb.ToString().TrimEnd(' ') + "..."; }
You need to login to post a comment.
