• 在字符串中找含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含有的以递归的方式找出来。

  • 相关阅读:
    【数位dp】Beautiful Numbers @2018acm上海大都会赛J
    【状压dp】Trie 树 @中山纪念中学20170304
    两个给点染色的问题-树上染色与图上染色
    【贪心】经营与开发 @upc_exam_5500
    【二分+拓扑排序】Milking Order @USACO 2018 US Open Contest, Gold/upc_exam_6348
    【并查集】Connectivity @ABC049&amp;ARC065/upcexam6492
    【倍增】T-shirt @2018acm徐州邀请赛 I
    Sparse Coding: Autoencoder Interpretation
    Sparse Coding
    Pooling
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1956342.html
Copyright © 2020-2023  润新知