/ Published in: C#
Expand |
Embed | Plain Text
private string TrimLength(string text, int length) { string output = text; if (text.Length > length) output = text.Substring(0, length - 1) + "..."; return output; } private string TruncateWords(string text, int wordCount) { string output = String.Empty; if (text.Length > 0) { try { string[] words = text.Split(' '); if (words.Length < wordCount) wordCount = words.Length; for (int x = 0; x <= wordCount; x++) output += words[x] + " "; if (words.Length > wordCount) output = output.Trim() + "..."; } catch { /* do nothing */ } } return output; }
You need to login to post a comment.
