阅读背景:

获取文本中所有的标签的位置,获取所有img标签的src

来源:互联网 
        public static int[] GetImagePos(string str)
        {
            str = str.Replace("$", " ");
            str = Regex.Replace(str, @"(?!<img.+?>)<.+?>", "");
            str = Regex.Replace(str, @"<img\b[^>]*>", "$");
            int startPos = 0;
            int foundPos = -1;
            int count = 0;
            List<int> foundItems = new List<int>();

            do
            {
                foundPos = str.IndexOf("$", startPos);
                if (foundPos > -1)
                {
                    startPos = foundPos + 1;
                    count++;
                    foundItems.Add(foundPos);
                }
            } while (foundPos > -1 && startPos < str.Length);

            return ((int[])foundItems.ToArray());
        }
        public static int[] GetImagePos(str



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: