首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

字符串截断步骤

2012-11-19 
字符串截断方法//中英混合字符串截断函数public static string getStr(string s, int l){string temp s

字符串截断方法
   //中英混合字符串截断函数
    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 "...";
    }

热点排行