zoukankan      html  css  js  c++  java
  • 在字符串中找含HTTP连接字符串的代码

          代码如下:

          private string GetHttpStr(string str, string httpStr)
            {
                bool Ishavevalue = false;
                int newlength = httpStr.Length;
                string newstr = null;

                string httpendString = "<";
                 if (str.Length >= newlength && str.Contains(httpStr))
                {
                    newstr = str.Substring(str.IndexOf(httpStr, StringComparison.OrdinalIgnoreCase) + newlength);
                }
                int startindex = 0;
                startindex = str.IndexOf(httpStr, StringComparison.OrdinalIgnoreCase);
                int lengthindex = 0;
                string returnvalue = null;
                if (startindex >= 0)
                {
                    if (newstr.IndexOf('"') != -1 && newstr.IndexOf('"') <= newstr.IndexOf(httpendString))
                    {
                        lengthindex = newstr.IndexOf('"') + newlength;
                    }
                    else if (newstr.IndexOf('"') == -1 && newstr.IndexOf(httpendString) == -1)
                    {
                        lengthindex = str.Length;
                    }
                    else
                    {
                        lengthindex = newstr.IndexOf(httpendString) + newlength;
                    }
                    if (lengthindex == (newlength - 1))
                    {

                        lengthindex = newstr.IndexOf(httpendString) + newlength;
                    }
                    returnvalue = str.Substring(startindex, lengthindex);
                    Ishavevalue = true;
                }
                returnvalue = ReplaceSpecialUrl(returnvalue);
                return returnvalue + "  " + ((startindex + lengthindex) < str.Length && startindex > 0 && Ishavevalue ? GetHttpStr(str.Substring(startindex + lengthindex), httpStr) : null);

            }

    因为HTTP连接在html都是以"结束或者<结束,所以根据传入的httpStr样式不区分大小写方式把字符串str含有的以递归的方式找出来。

  • 相关阅读:
    Dedecms sql命令批量修改内容
    dede 获取文章链接地址
    Sublime3 快捷键
    DEDE一些实用标签及自定义标签方法
    dedecms 制作模板中使用的全局标记介绍
    JS性能优化
    织梦channel标签currentstyle样式无效不起作用
    Dede 标签调用汇总
    dede标签:arclist标签使用大全
    CSS字体属性
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1956342.html
Copyright © 2011-2022 走看看