private string Method1(string text)

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

{
t = 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;
}
希望大家帮忙看看,有更好的方法请写出来
转载于:https://www.cnblogs.com/lizhengwei/archive/2008/02/26/1081648.html