重新设计一种权限体系的时候,遇到了一些问题,于是有了下面的一段代码,备份在此
看的懂俺这代码的,说明水平已经不错了 :)
protected
string
ParseAspxTag(
string
str)
... {
string s="";
int k,m,n;
string strKey="";
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:", "<");
//the following code just a simple solution,if string exist some word have not '"',add it
strKey = strKey.Replace(" ", " ");
for (int l = 0; l < strKey.Length; l++)
...{
if (strKey[l] == '='&&(strKey.Substring(1,l).Split('"').Length % 2)==1)
...{
if (strKey[l+1] != '"')
...{
int c=strKey.IndexOf(" ",l);
strKey = strKey.Insert(c, """);
strKey = strKey.Insert(l+1,""");
l = 0;
}
}
}
s += strKey + " ";
}
s = "<?xml version="1.0" encoding="utf-8"?><Root>" + s + "</Root>";
return s;
}
... {
string s="";
int k,m,n;
string strKey="";
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:", "<");
//the following code just a simple solution,if string exist some word have not '"',add it
strKey = strKey.Replace(" ", " ");
for (int l = 0; l < strKey.Length; l++)
...{
if (strKey[l] == '='&&(strKey.Substring(1,l).Split('"').Length % 2)==1)
...{
if (strKey[l+1] != '"')
...{
int c=strKey.IndexOf(" ",l);
strKey = strKey.Insert(c, """);
strKey = strKey.Insert(l+1,""");
l = 0;
}
}
}
s += strKey + " ";
}
s = "<?xml version="1.0" encoding="utf-8"?><Root>" + s + "</Root>";
return s;
}
俺没有使用正则表达式,俺不熟,习惯于使用笨办法解决简单问题