您的位置:首页 > 其它

.net 文字调用文字限制

2012-03-14 10:06 99 查看
调用文字字符限制:

public static string StringTruncat(string oldStr, int maxLength, string endWith)
{
if (string.IsNullOrEmpty(oldStr))
//   throw   new   NullReferenceException( "原字符串不能为空 ");
return oldStr + endWith;
if (maxLength < 1)
throw new Exception("返回的字符串长度必须大于[0] ");
if (oldStr.Length > maxLength)
{
string strTmp = oldStr.Substring(0, maxLength);
if (string.IsNullOrEmpty(endWith))
return strTmp;
else
return strTmp + endWith;
}
return oldStr;
}


前台调用:

<%# StringTruncat(Eval("PinPaiPingJia").ToString(), 100, "...")%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: