备份一段代码,不牛X

重新设计一种权限体系的时候,遇到了一些问题,于是有了下面的一段代码,备份在此

看的懂俺这代码的,说明水平已经不错了  :)

   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;
    }

 

俺没有使用正则表达式,俺不熟,习惯于使用笨办法解决简单问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值