您的位置:首页 > Web前端 > HTML

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

2015-09-07 17:50 411 查看
/// <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;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: