• 截取字符串并去掉图片


     /// <summary>
            /// 截取字符串并去掉图片
            /// </summary>
            /// <param name="content">要处理的字符串</param>
            /// <param name="length">截取长度</param>
            /// <param name="tail">尾部特定字符</param>
            /// <returns></returns>
            public static string CutWithoutPic(string content, int length, string tail)
            {
                int conlength = content.Length;
                int begin = 0;
                int end = 0;
                int endcharlen = 3;
                string result = "";
                begin = content.ToLower().IndexOf("<img ", 0);
                if (begin == -1)
                {
                    begin = content.ToLower().IndexOf("<input type=\"image", 0);
                    if (begin != -1)
                    {
                        end = content.ToLower().IndexOf("/>", begin);
                        if (end == -1)
                        {
                            end = content.ToLower().IndexOf(">", begin);
                            endcharlen = 2;
                        }
                        if (end == -1)
                            end = content.ToLower().IndexOf("/ >", begin);
                        result += content.Substring(0, begin);
                        result += content.Substring(end + endcharlen);
                    }
                }
                result = content;
                return CutString(result, length, tail);
            }
    /// <summary>
            /// 按长度截取字符串并在尾部添加特定字符
            /// </summary>
            /// <param name="str">原字符串</param>
            /// <param name="length">截取长度</param>
            /// <param name="tail">尾部特定字符</param>
            /// <returns>返回截取后含有尾部的字符串</returns>
            public static string CutString(string str, int length, string tail)
            {
                if (string.IsNullOrEmpty(tail))
                    tail = "...";
                if (str.Length < length)
                    return str;
                else
                    return str.Substring(0, length) + tail;
            }
  • 相关阅读:
    scroll事件实现监控滚动条改变标题栏背景透明度(zepto.js )
    瀑布流-转载
    如何清除img图片下面有一片空白
    加减号改变input[type=number]的数值,基于[zepto.js]
    如何移除HTML5的type=""number""的input标签的上下箭头
    滑屏框架
    GO_06:GO语言基础之struct
    GO_05:GO语言基础map与函数
    GO_04:GO语言基础条件、跳转、Array和Slice
    GO_03:GO语言基础语法
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2001541.html
Copyright © 2020-2023  润新知