/// <summary>
/// 获取固定长度的字符串(支持中英混合) 界面上长度一致
/// </summary>
/// <param name="str">需要截取的字符串</param>
/// <param name="length">需要截取的长度</param>
/// <returns></returns>
public static string GetFixedLenStr(string str,int length)
{
string temp = str;
if (Regex.Replace(temp,"[\u4e00-\u9fa5]","zz",RegexOptions.IgnoreCase).Length<=length)
{
return temp;
}
for (int i=temp.Length;i>=0;i--)
{
temp = temp.Substring(0,i);
if (Regex.Replace(temp,"[\u4e00-\u9fa5]","zz",RegexOptions.IgnoreCase).Length<=length-3)
{
return temp + "...";
}
}
return "...";
}
}
转自:http://yao.cnblogs.com/archive/2006/07/04/442886.html