首页 > Web开发 > 详细

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

时间:2015-09-07 18:00:37      阅读:321      评论:0      收藏:0      [点我收藏+]
/// <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;
        }

  

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

原文:http://www.cnblogs.com/jecob/p/4789526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!