C# 清除某個標簽的屬性值 源代碼


    /// <summary>
        /// 清除某個標簽的屬性值     寧夏大學 張冬 zd4004.blog.163.com
        /// </summary>
        /// <param ></param>
        /// <param ></param>
        /// <returns></returns>
        private string clearOneTag(string data, string tagn, string valc)
        {
            int stN = 0;

                  if (stN >= data.Length)
            {
                goto XUI;
            }

            int a1 = data.IndexOf("<" + tagn, stN);  //123456  23   56

            if (a1 + tagn.Length >= data.Length)
            {
                goto XUI;
            }

            int a2 = data.IndexOf(">", a1 + tagn.Length + 1);

 

            if ((a1 > -1) & (a2 > -1))
            {
                string s1 = data.Substring(0, a1 + tagn.Length + 1);
                string s2 = data.Substring(a2, data.Length - a2);
                string ss = data.Substring(a1 + tagn.Length + 1, a2 - a1 - tagn.Length - 1);

                      // href="http://www.baidu.com/"

                ss = ss.Trim();

                if (ss.IndexOf(" ") == -1)
                {
                    ss = " " + clearDat(ss, valc);
                }
                else
                {
                    string newX = "";
                    string[] mcc = ss.Split(' ');
                    foreach (string a in mcc)
                    {
                        if (a.Length > 0)
                        {
                            newX = newX + " " + clearDat(a, valc);
                        }
                    }
                    ss = newX;
                }

                stN = s1.Length + ss.Length;
                data = s1 + ss + s2;

                goto XDX;
            }

       
            return data;
        }

 

        /// <summary>

        /// 清除某個 值       寧夏大學 張冬 zd4004.blog.163.com

        /// </summary>

        /// <param ></param>

        /// <returns></returns>

        private  string clearDat(string dat, string valc)

        {

            string du = dat;

            //href="http://www.baidu.com/"

            dat = dat.Trim();

            if (dat.IndexOf(valc) != 0)

            {

                return dat;

            }

            return "";

            return "k";

            int c1 = dat.IndexOf("/"");

            if (c1 + 1 >= dat.Length)

            {

                goto HGH;

            }

            int c2 = dat.LastIndexOf("/"");

            if ((c1 <= -1) | (c2 <= -1) | (c1 >= c2))

            {

                goto HGH;

            }

            // string s1 = dat.Substring(0, c1 + 1);

            // string s2 = dat.Substring(c2, dat.Length - c2);

            string s1 = dat.Substring(0, c1);

            string s2 = dat.Substring(c2 + 1, dat.Length - c2 - 1);

            //  dat = s1 + dat.Substring(c1 + 1, c2 - c1 - 1) + s2 + "/r/n" + s1 + "/r/n" + s2;

            dat = s1 + s2;

        HGH:

            return dat;

        }

 

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: