/// <summary>
/// 截取指定数量字符中英混排
/// </summary>
/// <param name="str">要截取的字符串变量</param>
/// <param name="length">要截取的长度</param>
/// <param name="flag">flag=false表示不需要加省略号</param>
/// <param name="author">wangsdong</param>
/// <param name="from">www.aspbc.com</param>
/// <returns></returns>
public static string GetSubString(string str, int length, bool flag)
{
string temp = str;
int j = 0;
int k = 0;
for (int i = 0; i < temp.Length; i++)
{
if (Regex.IsMatch(temp.Substring(i, 1), @"[\u4e00-\u9fa5]+"))
{
j += 2;
}
else
{
j += 1;
}
if (j <= length)
{
k += 1;
}
if (j >= length)
{
temp = temp.Substring(0, k);
break;
}
}
if (flag)
{
temp += "...";
}
return temp;
}