// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class MainClass { private static char[] par = { '(', ')' }; public static bool MoreThanTwoPar(string s) { int ix = 0; int n = 0; for(;;) { ix = s.IndexOfAny(par, ix) + 1; if(ix > 0) { n++; if(n > 2) { return true; } } else { break; } } return false; } public static void Main(string[] args) { Console.WriteLine(MoreThanTwoPar("aa")); Console.WriteLine(MoreThanTwoPar("aa(bb")); Console.WriteLine(MoreThanTwoPar("aa(bb)cc")); Console.WriteLine(MoreThanTwoPar("aa(bb)cc(dd")); Console.WriteLine(MoreThanTwoPar("aa(bb)cc(dd)ee")); Console.WriteLine(MoreThanTwoPar("()")); Console.WriteLine(MoreThanTwoPar("()()")); Console.ReadLine(); } } }