欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#完美截斷字符串代碼(中文+非中文)

 更新時間:2012年08月29日 00:05:42   作者:  
c#完美截斷字符串代碼(中文+非中文),需要的朋友可以參考下
復(fù)制代碼 代碼如下:

public static string Truncation(this HtmlHelper htmlHelper, string str, int len)
{
if (str == null || str.Length == 0 || len <= 0)
{
return string.Empty;
}
int l = str.Length;
#region 計算長度
int clen = 0;
while (clen < len && clen < l)
{
//每遇到一個中文,則將目標(biāo)長度減一。
if ((int)str[clen] > 128) { len--; }
clen++;
}
#endregion
if (clen < l)
{
return str.Substring(0, clen) + "...";
}
else
{
return str;
}
}

相關(guān)文章

最新評論