C#中英文混合字符串过长截断

 /// <summary>
/// 截断字符串
/// </summary>
/// <param name="maxLength">最大长度</param>
/// <param name="str">原字符串</param>
/// <returns></returns>
public static string CutStr(int maxLength, string str)
{
string temp = str;
if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= maxLength)
{
return temp;
}
for (int i = temp.Length; i >= ; i--)
{
temp = temp.Substring(, i);
if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= maxLength - )
{
return temp + "...";
}
}
return "...";
}
上一篇:git merge 和 git rebase 小结(转)


下一篇:python中的基本数据类型之列表,元组