using System.Text.RegularExpressions;using System.Text;////// 字符串长度(按字节算)/// /// ///static int StrLength(string str){ int len = 0; byte[] b; for (int i = 0; i < str.Length; i++) { b = Encoding.Default.GetBytes(str.Substring(i,1)); if (b.Length > 1) len += 2; else len++; } return len;}/// /// 截取指定长度字符串(按字节算)/// /// /// ///static string StrCut(string str, int length){ int len = 0; byte[] b; StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.Length; i++) { b = Encoding.Default.GetBytes(str.Substring(i, 1)); if (b.Length > 1) len += 2; else len++; if (len >= length) break; sb.Append(str[i]); } return sb.ToString();}