去除重复字符串,效率

 private string Method1(string text)
    
{
        
string t = text;
       
// t = Regex.Replace(t, @"(.)\1+", "$1");
       
        
while (Regex.IsMatch(t, @"(.+|.)([^\1]*?)(\1)"))//(.)([^\1]+?)(\1)
        {
           
= Regex.Replace(t, @"(.+|.)([^\1]*?)(\1)""$1$2");
        }

         return t;

       
    }

    
private string Method2(string text)
    
{
        
string t =text;
        
//t = Regex.Replace(t, @"(.)\1+", "$1");
        int i = 0;
        
while (Regex.IsMatch(t, @"(.)([^\1]*?)(\1)"))
        
{
            i
++;
            t 
= Regex.Replace(t, @"(.)([^\1]*?)(\1)""$1$2");
        }

       
// atb2.Text = Regex.Replace(t, @"(.)\1+", "$1");
       
            Response.Write(i);return t;
    }
希望大家帮忙看看,有更好的方法请写出来
posted @ 2008-02-26 09:54  lzwlfw  阅读(408)  评论(1编辑  收藏  举报