// 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 { class MainClass { public static int CountOccur(string str, string substr) { int res = 0; int ix = 0; while((ix = str.IndexOf(substr, ix)) >= 0) { ix += substr.Length; res++; } return res; } public static void Main(string[] args) { Console.WriteLine(CountOccur("abcabcacabbc", "ab")); } } }