1)方法:
public static string SubStr1(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;
}
前台调用:
<%#SubStr1(Eval("Zt").ToString(),10,"...")%>
2)方法:
public string SubStr(string sString, int nLeng) ///实现和上面的方法同样的功能
{
if (sString.Length <= nLeng)
{
return sString;
}
int nStrLeng = nLeng - 3;
string sNewStr = sString.Substring(0, nStrLeng);
sNewStr = sNewStr + "...";
return sNewStr;
}
前台调用:<%#SubStr(Eval("Zt").ToString(),10)%>
?

本文原创,转载请注明出处!!
本文地址:http://happysnail.org/index.php/archives/74