您的位置:首页 > 其它

.NET截取指定长度汉字超出部分以“…”代替

2011-04-23 07:35 225 查看
public static string StringTruncat(string oldStr, int maxLength, string endWith)
{
if (string.IsNullOrEmpty(oldStr))
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: