Published in: C#
public static string TruncateChar(string strText, int intCharCount) { string strReturn = ""; try { if (strText.Length > intCharCount) strReturn = strText.Substring(0, intCharCount) + "..."; else strReturn = strText; } catch { } return strReturn; } public static string TruncateWords(string strText, int intWordCount) { string strReturn = ""; try { string[] strWords = strText.Split(' '); if (strWords.Length < intWordCount) intWordCount = strWords.Length; for (int x = 0; x <= intWordCount; x++) strReturn += strWords[x] + " "; if (strWords.Length > intWordCount) strReturn = strReturn.Trim() + "..."; } catch { /* do nothing */ } return strReturn; }
You need to login to post a comment.
