Task:
You must write a program that will remove the same, adjacent characters from an arbitrary string. At the same time, if at the removal of these characters a pair of identical adjacent characters again appears, they should also be removed. Here are a few tests to check:
/*balloon -> ban book -> bk affah -> h essence -> nce void Main()*/ { var src = @"balloon-ban book-bk affah-h essence-nce"; var lines = src.Split('\n'); foreach (var line in lines) { var words = line.Trim().Split('-'); Debug.Assert(Foo(words[0]) == words[1], $"Foo({words[0]}) return: { Foo(words[0])}, excpected: {words[1]}"); } } string Foo(string s) { s = Regex.Replace(s,@"\S{2}",""); return s; } My method removes all duplicate characters, I can not find the desired pattern
\S{2,}- nick_n_a\S{2,}as well as\S{2}removes all duplicates, i.e. and the symbols b and a and n, in those cases where they should stay - stasynyoabaabcwhat should be left of it? - Mikeac. That is:$s =~ s/(.)\1+//g while $s =~ /(.)\1/;- PinkTux