/// <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;
}
原文:http://www.cnblogs.com/jecob/p/4789526.html