`
lwyingdao
  • 浏览: 19403 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类

字符串截断方法

 
阅读更多
   //中英混合字符串截断函数
    public static string getStr(string s, int l)
    {
        string temp = s;
        if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= l)
        {
            return temp;
        }
        for (int i = temp.Length; i >= 0; i--)
        {
            temp = temp.Substring(0, i);
            if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= l - 3)
            {
                return temp + "...";
            }
        }
        return "...";
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics