.net 文字调用文字限制
调用文字字符限制:
1 public static string StringTruncat(string oldStr, int maxLength, string endWith)
2 {
3 if (string.IsNullOrEmpty(oldStr))
4 // throw new NullReferenceException( "原字符串不能为空 ");
5 return oldStr + endWith;
6 if (maxLength < 1)
7 throw new Exception("返回的字符串长度必须大于[0] ");
8 if (oldStr.Length > maxLength)
9 {
10 string strTmp = oldStr.Substring(0, maxLength);
11 if (string.IsNullOrEmpty(endWith))
12 return strTmp;
13 else
14 return strTmp + endWith;
15 }
16 return oldStr;
17 }
前台调用:
<%# StringTruncat(Eval("PinPaiPingJia").ToString(), 100, "...")%>