去除重复字符串,效率
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;
}


浙公网安备 33010602011771号