// 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; using System.Text.RegularExpressions; class MainClass { public static void Main(string[] args) { test("A"); test("Arne"); test("V"); test("AB"); test("VA"); } private static void test(string s) { Console.WriteLine(s + " " + HasABC(s) + " " + HasABCregexp(s) + " " + IsAllABC(s)); } private static char[] xc = { 'A', 'B', 'C' }; public static bool HasABC(string s) { return (s.IndexOfAny(xc) >= 0); } public static bool HasABCregexp(string s) { return Regex.IsMatch(s, "[A-C]"); } public static bool IsAllABC(string s) { return s.Equals(Regex.Match(s,"[A-C]*").Value); } }