简单判断某字符是否在html标签中

/// <summary>
        /// 判断某个字符是否在html 属性里面
        /// </summary>
        /// <param name="content"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private static bool IsInHtmlAttribute(string content, int index)
        {
            bool result = false;
            bool pre=false,post=false;
            int preIndex = index, postIndex = index;
            while (preIndex >= 0 && (content[preIndex] != '\'' && content[preIndex] != '"'))
            {
                preIndex--;
            }
            if (preIndex > 0)
            {
                //不是结束属性符号
                if (content[preIndex + 1] != ' ' && content[preIndex -1]=='=')
                {
                    pre = true;
                }
            }
            while (postIndex < content.Length && (content[postIndex] != '\'' && content[postIndex] != '"'))
            {
                postIndex++;
            }
            if (postIndex < content.Length)
            {
                if ((content[postIndex + 1] == ' ' || (content[postIndex + 1] == '/' && content[postIndex + 2] == '>')) && content[postIndex -1] != '=')
                {
                    post = true;
                }
            } 
            if(pre &&post)
            {
                result=true;
            }
            return result;
        }

  

posted @ 2015-09-07 17:50  枯树之花  阅读(1338)  评论(0编辑  收藏  举报