日期:2014-05-18 浏览次数:21017 次
string test_str = "abcabc12345612ab"; test_str = string.Join("", test_str.ToArray().Distinct());//abc123456
------解决方案--------------------
void Main() { string str="abcabc12345612ab"; Regex reg = new Regex(@"((\w)\w*?)\2"); while (str != (str = reg.Replace(str, "$1"))) { } Console.WriteLine(str); //abc123456 } //不过我还是建议你用LINQ来实现,这不是正则干的活~~~
------解决方案--------------------
Regex regex = new Regex(@"(\w)(?=.*?\1)"); string str = "abcabc12345612ab"; Response.Write(regex.Replace(str,""));
------解决方案--------------------
string str="abcabc12345612ab"; str=new string(str.ToCharArray().Distinct().ToArray());
------解决方案--------------------
支持一楼