asp.net 页面截取一定长度(显示长度)字符串函数

来源:互联网 发布:爱奇艺网络电影 编辑:程序博客网 时间:2024/05/18 11:31

public static string SubstringByte(string text, int startIndex, int length)
    {
        Encoding _encoding = System.Text.Encoding.GetEncoding("GB2312");
        byte[] bytes = _encoding.GetBytes(text);
        try
        {
            return _encoding.GetString(bytes, startIndex, length).Replace("?", "") + "...";
        }
        catch
        {
            return text;
        }
    }

原创粉丝点击