/// <summary> /// 截取字符串,中文安两个字符处理 /// </summary> /// <param name="stringToSub"></param> /// <param name="length"></param> /// <returns></returns> public static string GetFirstString(object stringToSub, int length) { Regex regex = new Regex("[u4e00-u9fa5]+", RegexOptions.Compiled); char[] stringChar = stringToSub.ToString().ToCharArray(); StringBuilder sb = new StringBuilder(); int nLength = 0; for (int i = 0; i < stringChar.Length; i++) { if (regex.IsMatch((stringChar[i]).ToString())) { sb.Append(stringChar[i]); nLength += 2; } else { sb.Append(stringChar[i]); nLength = nLength + 1; } if (nLength > length) { break; } } return sb.ToString(); }