码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-09-07 18:02:16      阅读:177      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!