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含有的以递归的方式找出来。

  • 相关阅读:
    剑指offer-二维数组中的查找
    TF-IDF(term frequency–inverse document frequency)
    Java实现中文字符串的排序功能
    当前课程
    【R】资源整理
    CentOS相关
    【转】Setting up SDL Extension Libraries on MinGW
    【转】Setting up SDL Extension Libraries on Visual Studio 2010 Ultimate
    【转】Setting up SDL Extension Libraries on Code::Blocks 12.11
    【转】Setting up SDL Extension Libraries on Visual Studio 2019 Community
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1956342.html
Copyright © 2011-2022 走看看