#region 截短字串的函数,兼容中英文 /// <summary> /// 截短字串的函数,兼容中英文 /// </summary> /// <param name="mText">要加工的字串</param> /// <param name="byteCount">长度</param> /// <returns>被加工过的字串</returns> public static string Left(string mText, int byteCount) { if (byteCount < 1) return mText; if (System.Text.Encoding.Default.GetByteCount(mText) <= byteCount) { return mText; } else { byte[] txtBytes = System.Text.Encoding.Default.GetBytes(mText); byte[] newBytes = new byte[byteCount - 4]; for (int i = 0; i < byteCount - 4; i++) { newBytes[i] = txtBytes[i]; } string OutPut = System.Text.Encoding.Default.GetString(newBytes) + "..."; if (OutPut.EndsWith("?...") == true) { OutPut = OutPut.Substring(0, OutPut.Length - 4); OutPut += "..."; } return OutPut; } } #endregion