/// 字符截取,中文一个字符两个字节处理
/// </summary>
/// <param name="str"></param>
/// <param name="length"></param>
/// <returns></returns>
public static string SubString(string str, int length)
{
Regex regex = new Regex("^[\u4e00-\u9fa5]$");
StringBuilder sb = new StringBuilder();
int nLength = 0;
for (int i = 0; i < str.Length; i++)
{
if (regex.IsMatch((str[i]).ToString()))
{
sb.Append(str[i]);
nLength += 2;
}
else
{
sb.Append(str[i]);
nLength = nLength + 1;
}
if (nLength >= length)
break;
}
return sb.ToString();
}