/**/ /// <summary> /// 精确截取字符串长度 /// </summary> /// <param name="str">字符串</param> /// <param name="length">截取的长度</param> /// <returns>返回截取后的字符串</returns> public static string CutString( string str, int length) ... { return CutString(str,length,".."); } /**/ /// <summary> /// 精确截取字符串长度 /// </summary> /// <param name="str">需要截取的字符串</param> /// <param name="length">截取的字符串长度</param> /// <param name="overstr">大于截取部分表示方式</param> /// <returns></returns> public static string CutString( string str, int length, string overstr) ... { length=length*2; str = str.Trim(); byte[] buffer1= Encoding.Default.GetBytes(str); if (buffer1.Length > length) ...{ string text1 = ""; for (int num1 = 0; num1 < str.Length; num1++) ...{ byte[] buffer2 = Encoding.Default.GetBytes(text1); if (buffer2.Length >= length) ...{ break; } text1 = text1 + str.Substring(num1, 1); } return (text1 +overstr); } return str; }