public string StrName(object o,int length)
{
if (o != null)
{
string content = o.ToString();
Encoding encoding = Encoding.GetEncoding("gb2312");
StringBuilder sb = new StringBuilder();
int totalLength = 0;
foreach (char contentChar in content)
{
int size = encoding.GetByteCount(new char[] { contentChar });
if (totalLength + size > length - 2)
{
sb.Append("....");
break;
}
sb.Append(contentChar);
totalLength += size;
}
return sb.ToString();
}
else