重新设计一种权限体系的时候,遇到了一些问题,于是有了下面的一段代码,备份在此
看的懂俺这代码的,说明水平已经不错了 :)
protectedstringParseAspxTag(stringstr)
...{
strings="";
intk,m,n;
stringstrKey="";
while(str.IndexOf("<asp:")>0)
...{
k=str.IndexOf("<asp:");
m=0;
n=k;
while(m==0)
...{
m=str.IndexOf(">",n);
if((str.Substring(k,m-k+1).Split('"').Length%2)==0)
...{
n=m+1;
m=0;
}
else
...{
strKey=str.Substring(k,m-k+1);
str=str.Replace(strKey,"");
if(strKey.IndexOf("/>")<=0)
...{
strKey=strKey.Replace(">","/>");
}
break;
}
}
strKey=strKey.Replace("<asp:","<");
//thefollowingcodejustasimplesolution,ifstringexistsomewordhavenot'"',addit
strKey=strKey.Replace(" ","");
for(intl=0;l<strKey.Length;l++)
...{
if(strKey[l]=='='&&(strKey.Substring(1,l).Split('"').Length%2)==1)
...{
if(strKey[l+1]!='"')
...{
intc=strKey.IndexOf("",l);
strKey=strKey.Insert(c,""");
strKey=strKey.Insert(l+1,""");
l=0;
}
}
}
s+=strKey+" ";
}
s="<?xmlversion="1.0"encoding="utf-8"?><Root>"+s+"</Root>";
returns;
}
俺没有使用正则表达式,俺不熟,习惯于使用笨办法解决简单问题
本文介绍了一种不使用正则表达式的ASP.NET标签解析方法。作者通过一系列字符串操作实现了对ASP.NET标签的解析与重组,并将结果转换为XML格式。这种方法虽原始但有效,适合希望了解底层实现细节的读者。
1356

被折叠的 条评论
为什么被折叠?



